Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open file in iTerm vim for MacOS Sierra
-- TerminalVim.app
-- 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 TerminalVim.app 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
@chaadow

This comment has been minimized.

Copy link

commented Dec 23, 2016

Thank you very much. I am running MacOS El capitan and it works.

May I suggest removing line number 13, because in my case, wether iTerm is open or not, it creates two windows : One with the file open, and one empty. ( maybe this is what you want? )

Additionnaly, I removed the & "; exit on line 16, so that I could close it as I would normally do if I ran the file directly from iTerm.

@dariocravero

This comment has been minimized.

Copy link

commented Mar 8, 2017

This is brilliant :) Thanks Charlie!

@IllyaStarikov

This comment has been minimized.

Copy link

commented May 2, 2017

THANK YOU. Been scavenging the internet for a while for something like this.

@ShiranC

This comment has been minimized.

Copy link

commented Aug 13, 2017

Thank you!

@natj

This comment has been minimized.

Copy link

commented Sep 29, 2017

Amazing! Thanks!

@sdkks

This comment has been minimized.

Copy link

commented Nov 23, 2017

Thank you. Took some inspiration from this and did one for nvim
https://gist.github.com/sdkks/a017564ea65a781a9ce416d716e08f1e

@xavierartot

This comment has been minimized.

Copy link

commented Dec 20, 2017

@sdkks
Nice, you make my day :), I just started Nvim

@KTGR771

This comment has been minimized.

Copy link

commented Aug 21, 2018

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

@waldganger

This comment has been minimized.

Copy link

commented Sep 18, 2018

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

@maartenq

This comment has been minimized.

Copy link

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"
        activate
        tell current window
            create tab with default profile command cmd
        end tell
    end tell
end run
@SilverEzhik

This comment has been minimized.

Copy link

commented Mar 14, 2019

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

https://gist.github.com/SilverEzhik/cec3f065e7ab7b93d9102df70fa60d9b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.