Open in iTerm Vim from Finder

Written . Tagged AppleScript, OS X, Vim.

When I double-click a code file in Finder, I want it to open in Vim in a terminal. Not in MacVim. Not in some lesser editor.

There’s plenty of prior work, but nothing worked well for me on OS X 10.10 Yosemite, so I rolled my own.

The end result: double-clicking a file opens a new iTerm window with the file opened in Vim.

Since it execs Vim (replaces the shell process), the window closes when you quit Vim. This also means you can’t ⌃Z out of the Vim session. Think of it as an editor window, not a full-fledged terminal.

1. Get an .app

Download, unzip it and stick the app in /Applications.

Or make your own:

  • Open Apple’s “Automator” app.
  • If you get a file dialog, opt to create a “New Document”.
  • Select the “Application” type.
  • Search the action list for “Run AppleScript”, double-click that option.
  • Change the script to this (hat tip to Rob Peck):
on run {input, parameters}
  set myPath to POSIX path of input
  set cmd to "vim " & quote & myPath & quote

  tell application "iTerm"
      set myTerm to (make new terminal)
      tell myTerm
          set mySession to (make new session at the end of sessions)
          tell mySession to exec command cmd
      end tell
  end tell
end run
  • Save as /Applications/

2. Tell Finder to use your app

  • In Finder, select some file you want to open in Vim, e.g. a .rb file.
  • Hit ⌘I to open the “Get Info” window.
  • Under “Open with:”, choose “”. You may need to select “Other…” and then browse.
  • Hit the “Change All…” button and confirm.

Now all .rb files in Finder will open in Vim.

3. Profit

That’s it!