Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
For which apps? –  Ignacio Vazquez-Abrams May 14 '11 at 13:37

2 Answers 2

up vote 3 down vote accepted

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:

enter image description here

share|improve this answer
    
that's great, but how about a new tab instead? –  matt ryan May 15 '11 at 14:22
    
@Matt See edited post. –  Daniel Beck May 15 '11 at 14:41
    
@daniel that works great, but if the app is not already open it launches with two tabs. –  matt ryan May 15 '11 at 15:16
    
@Matt It does what you want it to do. Nothing more, nothing less. Get your requirements in order. –  Daniel Beck May 15 '11 at 15:59
    
@Matt Better now? –  Daniel Beck May 15 '11 at 16:22

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.