0

I do a lot of programming and just starting to do a bit of web development. At the moment I am going to be making a few files and folders, because of this, is there a way to open a application in vim (in terminal not visual vim) when double/right clicking the file in finder?

Thanks

  • Any reason why gVim won't do? If you aren't already using Terminal.app it just seems a tad odd...Though there's always the argument for not installing more cruft on a system, I guess… – forquare Oct 26 '15 at 18:02
  • @forquare It's because after I have edited that file I would like to run some command line tools, for example when going back to C++, I would like to run the g++ command then execute it after saving the file. I also don't want to download another application unless I have to. – iProgram Oct 26 '15 at 18:26
1

Create an Applet. The script below should get you started. Save that Applet to place of your preference (/Applications/). Select any text file and press ⌘+I(nfo) > Open With: > Other > Select you Applet, then click change all. Now whenever you open any text file that applet will run, which will open the file in vim.

on open theFiles
    tell application "Terminal"
        activate
        -- If there are no open windows, open one.
        if (count of windows) is less than 1 then
            do script ""
        end if
        set theTab to selected tab in first window
        set filePath to POSIX path of item 1 of theFiles
        do script "/usr/bin/vim " & quoted form of filePath in theTab
    end tell
    return
end open

on run
    --  Handle the case where the script is launched without any dropped files
    open (choose file with multiple selections allowed)
    return
end run
  • Good point! I could then put this in automator and set it as a service, which will then allow me to have a keyboard shortcut. Thanks – iProgram Oct 27 '15 at 10:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .