Create a Vim app for Mac OS X

On occasion it is nice to have a way to open a file in Vim without having to jump over to the terminal. I researched a few GUI options like VimR or MacVim and others but all had problems. MacVim didn’t support FZF and wasn’t built on Neovim, VimR and others didn’t quite feel polished/stable enough.

After a bit more research and trial and error I found that I could create an Automator app with an AppleScript which would accomplish what I wanted.

Here is the script if you want to try it out.

on run {input, parameters}
  try
    set filePath to POSIX path of input
  on error errMsg
    set filePath to ""
  end try

  tell application "iTerm"
    create window with default profile
    tell front window
      tell current session
        if filePath is "" then
          write text ("vim; exit")
        else
          write text ("vim " & quote & filePath & quote & "; exit")
        end if
      end tell
    end tell
  end tell
end run

To use this script, open Automator and create a new Application, then choose “Run AppleScript” and drag it into the workflow. Paste the above script in then save the application and you are ready to go. This script opens iTerm but it could be modified to use Terminal too.