Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Open file in iTerm vim for MacOS Sierra
-- This creates a shim Application that will enable you to open files from the Finder in vim using iTerm
-- To use this script:
-- 1. Open Automator and create a new Application
-- 2. Add the "Run Applescript" action
-- 3. Paste this script into the Run Applescript section
-- 4. Save the application as in your Applications folder
-- 5. In the Finder, right click on a file and select "Open With". In that window you can set TerminalVim as a default
on run {input, parameters}
tell application "iTerm"
create window with default profile
tell front window
tell current session
write text ("vim " & quote & POSIX path of input & quote & "; exit")
end tell
end tell
end tell
end run
Copy link

waldganger commented Sep 18, 2018

Many thanks for this script. It works on High Sierra.

Copy link

maartenq commented Oct 20, 2018

It works.Thanks!And I think It will be great if can creat new tab when iTerm is running.

for opening in a new tab in possible opened iTerm2 (3.2.3 on OS X Mojave)

on run {input, parameters}
    set myPath to POSIX path of input
    set cmd to "vim " & quote & myPath & quote
    tell application "iTerm"
        tell current window
            create tab with default profile command cmd
        end tell
    end tell
end run

Copy link

SilverEzhik commented Mar 14, 2019

I made a version of this that handles opening multiple files.

Copy link

cinakyn commented Oct 29, 2019

Above is cominated version of above. thanks authors.

  • multiple file wil be open with multiple vim tabs
  • new window will be created if not exist.
  • new tab will be created if window is not new one

Copy link

normen commented Apr 25, 2020

Heres my two versions

  • One edits any selected text in place (e.g. in Mail, Safari etc.) on recent MacOS versions
  • The other can open files as an app or a quick action, just like the versions here. It also supports multiple files (tabs) and .vim session files.

Grab here:

Copy link

dkarter commented May 1, 2020

So good! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment