Skip to content

Instantly share code, notes, and snippets.

@AdrienGiboire
Forked from Huluk/gist:5117702
Last active September 10, 2015 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrienGiboire/adc7ef08c8f8b5089dd4 to your computer and use it in GitHub Desktop.
Save AdrienGiboire/adc7ef08c8f8b5089dd4 to your computer and use it in GitHub Desktop.
Open Files with Terminal Vim by default [mac, iterm]
If you want your terminal vim to open files you double click, follow the following steps (MacOS only):
1. Open Automator
2. Select Application
3. Copy the attached file
4. Save and set as default for opening files
Multiple files are opened in vim tabs.
If there is already a vim instance running, files are opened in it.
Bugs / Problems:
- does not open files when vim instance is in insert mode
- vim instances running e.g. in tmux are not recognized
Also thank Daniel Beck, who posted the script I adjusted
http://superuser.com/questions/283418/how-can-i-make-terminal-vim-my-default-editor-application-in-mac-os-x
on run {input, parameters}
if (count of input) > 0 then
tell application "System Events"
set runs to false
try
set p to application process "iTerm"
set runs to true
end try
end tell
tell application "iTerm"
activate
if (count of terminals) = 0 then
make new terminal
end if
set numItems to the count of items of input
set numTerms to the count of terminals
set launchPaths to ""
repeat with t from 0 to (numTerms - 1)
tell item (numTerms - t) of terminals
if (count of sessions) = 0 then
launch session "Default"
end if
repeat with s from 1 to count of sessions
set currentSession to item s of sessions
if name of currentSession contains "vim" then
tell currentSession
write text (":silent! tablast")
repeat with x from 1 to numItems
set filePath to quoted form of POSIX path of item x of input
write text (":execute 'tabedit '.fnameescape(" & filePath & ")")
end repeat
return
end tell
end if
end repeat
end tell
end repeat
tell current terminal
tell (launch session "Default")
repeat with x from 1 to numItems
set filePath to quoted form of POSIX path of item x of input
set launchPaths to launchPaths & " " & filePath
end repeat
write text ("mvim -p " & launchPaths)
end tell
end tell
end tell
end if
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment