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 have defined my own custom vim file type with highlighting etc. I would like to open it using the terminal based vim when I double click on it. I am using mac os x. Any pointers on how to start on this?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

Create an Automator Application to run the following applescript:

on run {input}
   set the_path to POSIX path of input
   set cmd to "vim " & quoted form of the_path
   tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
   tell application "Terminal"
      activate
      if terminalIsRunning is true then
         do script with command cmd
      else
         do script with command cmd in window 1
      end if
   end tell
end run

Save the automator application. (eg. name it Vim Launcher)

Right click (or control-click) on your custom vim-type file (eg. use .vim as the extension) and under Open With… choose the bottom option Other… and find your Automator Application (eg. Vim Launcher), double-click it.

Boom.

share|improve this answer
    
To create in Automator, you can click New Document, select the Application template. In the Actions->Library tab, click Utilities, then Run AppleScript. –  cevaris Aug 24 at 15:51

From the five or so minutes I spent playing with it to see if it would I couldn't find a built -in option to do so.

However, you can probably write a simple Applescript that will take the files absolute path and then run vim {path} in a bash shell.

share|improve this answer
set the_path to POSIX path of input
   set cmd to "vim " & quoted form of the_path & "; exit"
   tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
   tell application "Terminal"
      if terminalIsRunning is true then
         do script with command cmd
      else
         do script with command cmd in window 1
      end if
      activate
   end tell
end run

I use this AppleScript instead. It activates Terminal.app after (not before!) execution to stop things from acting odd when using Spaces. It also closes the window after Vim exits. Just set Terminal.app to close after clean exits.

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.