Send To vim for MacOSX

Published on 14 Oct 2008 at 11:07 pm. No Comments.
Filed under Mac.

Vi is still the greatest editor ever. I guess I never really learned how to use Emacs properly. One of the first things I do when I configure a computer is install VIM and setup a “send to vim” right click (comand) context menu. With vim available already as a command line I figured I could probably write some apple script to start a terminal and fire up VIM using the context menu.

A visit to the VIM site informed me that there was a MacVim Project which looked nice. I enjoyed the graphical version of VIM for windows so I grabbed that. It had an integration option that added a menu to safari and some other apps allowing me to select to edit in MacVim, but didn’t integrate into the context menu.

A little more searching lead me to OnMyCommand. Wow. This thing is just awesome. Once installed there are a ton of pre created onCommand scripts to choose from. Everything from basic stuff like “Move To” and “Copy To” to CVS checkin, graphic file conversions from one format to another, MD5 hash generation, man page lookups, all kinds of stuff.

One thing that I already loved about MacOSX was that when I highlighted some text the context menu already had “Look Up in Google” and “Look up in Dictionary”. A high % of the time when I highlight text it’s gonna end up in google’s search box. Another really cool feature I found was drag to paste. Nothing is really as fast as command-c, command-v but you can also highlight some text and drag it to another area that accepts text, including terminal windows and it automatically copy and pastes the text. Another nice little surprise touch.

So back to the VIM.  I found a script on that page that said it would edit the file contents in a terminal with vi. That seemed like a step in the right direction.

Back in the OMC directory is a program called OMCEdit, upon opening it up I found that I could download all of the pre-created scripts without having to go after each one individually….This just got a whole lot better. Once downloaded the script I was after at that time was #21. I installed the example scripts from the directory “Examples” > “First Time Users Start Here” as a quick way to write the config file and get the onMyCommand menu to show up. I then selected “Command Library” (ive already done the download at this point) and selected #21 and hit “Append To Commands”.

Boom now I had the ability to send to vi. This was the command line vi, and since I had just rebooted from installing it fired up 5 terminal windows (my standard terminal startup). However once terminal was already running it only fired up a single window, that window didn’t have my default settings for background and text color however.

So now I accomplished my original goal of having a context menu item to send a file to vim. However the gvim I just downloaded is pretty nice, so I want to add an onMyCommand for gvim. Back in Applications > OMC I fire up OMCEdit. I hit the little + in the bottom left corner to add a new Command. Title it “Edit file contents in Gvim” leave all other defaults the same and in the Command window I entered:

/usr/local/bin/mvim __OBJ_PATH__

mvim is the script that comes with Gvim that allows you to send a file from the terminal command line to gvim. I installed mvim in /usr/local/bin so I had to put the full path. If you installed it someplace a little smarter like /bin or /usr/bin you wont have to enter the full path. In fact just to be sure I moved mvim to /usr/bin and re-entered the command as:

mvim __OBJ_PATH__

Worked like a charm! So now I can send any file to vim in a terminal or gvim for editing.

Here is a pic of what the command looks like:

(click for larger version)

Comments are closed.