Add “Edit with VIM” to the OSX Context Menu

I’ve been using Vim for making quick changes to files in Unix and Windows for years. As a result I am used to right-clicking files with any extension and editing it with Vim from the context menu (or is it contextual menu? I forget). Often times before making changes to a file, I’ll make a copy of it and add “.bak” to the original file name’s extension. This way I can quickly go back if a change in the new file screws things up. Since the original file extension has been changed to .bak however, it has temporarily become a hassle to open it back up for viewing (because no default text editor is associated with .bak or .tmp files). Therefore having an Edit with Vim right-click context menu option which I can execute on any file type is essential for me. Here’s how to configure one in Snow Leopard using Automator.
[step 1] Download and install MacVim.

[step 2] Launch Automator and from the workflow template menu choose a Service template.

[step 3] From the Actions Library click Utilities. Now drag the “Run Shell Script” action to your Services workflow (the empty space on the right).

[step 4] From the Pass input: pull down select “as arguments” and enter the following into the script window.

open -a MacVim "$@"

automator shell script service workflow

[step 5] Save your workflow (the name you choose will be what’s displayed on the context menu – I saved mine as “Edit”). Now simply right-click any file in the Finder and select the context menu option you created to edit it with MacVim.

Edit context menu option in Snow Leopard

To enable/disable context menu services or to add keyboard shortcuts to them open Finder and click Services -> Services Preferences and find the service you created in the list. Simply un-check it to disable and/or click the space on the right to add a keyboard shortcut.

finder service preferences

NOTE: Curious as to where these workflows are stored? I was…it’s in /users/<username>/Library/Services.
That’s it.


Posted

in

by

Comments

3 responses to “Add “Edit with VIM” to the OSX Context Menu”

  1. Matt Avatar
    Matt

    Thanks! This is a very clean way of doing it. I really missed the context menu when moving to Mac.

  2. […] Add “Edit with VIM” to the OSX Context Menu | David Vielmetter [step 2] Launch Automator and from the workflow template menu choose a Service template . [step 1] Download and install MacVim . [step 3] From the Actions Library click Utilities . […]

  3. Wren Avatar
    Wren

    Thanks!