How can I make terminal VIM my default editor application in Mac OS X?
Solution 1
See my answer here, but use a Run AppleScript action in Automator instead and use the following AppleScript code:
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
set t to (make new terminal)
else
set t to current terminal
end if
tell t
tell (make new session at the end of sessions)
exec command ("vim \"" & POSIX path of first item of input as text) & "\""
end tell
if not runs then
terminate first session
end if
end tell
end tell
end if
end run
This'll open a new iTerm window if there's none, otherwise a new tab, and open the file in there. Result:
Solution 2
This is a very simple way to open files in terminal vim from iterm command click. It also jumps to the line number if it is specified. You will need to download one of the nightly builds to get the coprocess feature.
Click on: Preferences -> Profiles -> Advanced
Under "Semantic History", choose "Run coprocess..". In the text field, put: echo vim \1 +\2
source: https://coderwall.com/p/5hp1yg
Matt Ryan
Updated on September 18, 2022Comments
-
Matt Ryan almost 2 years
I am aware of MacVim, and while it's very nice I am constantly in the terminal. Why have two programs running when I could stay in one?
So the question is, how can I make VIM (run in iTerm2) the default text editor?
-
Matt Ryan about 13 yearsthat's great, but how about a new tab instead?
-
HikeMike about 13 years@Matt See edited post.
-
Matt Ryan about 13 years@daniel that works great, but if the app is not already open it launches with two tabs.
-
HikeMike about 13 years@Matt It does what you want it to do. Nothing more, nothing less. Get your requirements in order.
-
HikeMike about 13 years@Matt Better now?
-
Matt Ryan about 13 yearswell you certainly answered the original question, and then went a step further. thanks. but it doesn't actually terminate the empty session. and actually, it makes more sense to use the first as opposed to starting a new one and then closing the first. don't worry about it though... technically best practices are not requirements.
-
HikeMike about 13 years@Matt I didn't find any indicator on whether a session/terminal is in use. I have the same problem in Terminal. I like erring on the side of too many tabs better than taking over a shell in use (and possibly failing to do that).
-
Shadoath over 7 yearsThis no longer requires the nightly built of ITerm 2.
-
Ravindra Bawane about 4 yearsOP isn't still having the issue, based on the fact they selected an answer.
-
T_T over 2 years@DanielBeck It does not work on Monterey. It would be nice if you could modify it such that it also works on the latest macOS.