Running MacVim in your terminal

A recent version of Vim comes with every copy of Mac OS X. When Apple compiled it they didn't link it against Ruby, which means that you can't use /usr/bin/vi with any Ruby based plugins. MacVim (which includes Ruby support) normally runs with a GUI, but you can run it in a terminal when you type vi if you prefer.

If MacVim isn't already installed, go and download it now.

When you run MacVim using the application icon it runs a binary inside your Applications folder. MacVim's disk image also contains a script called mvim that you can put in a folder in your $PATH so that you can launch that same binary from the command line. If you haven't already done so, install the mvim script. You can get advice on how to do that by typing :help mvim inside MacVim; they recommend putting the script in /usr/local/bin.

To get the vi command to run MacVim without the GUI we can make a symlink to the mvim script, and call it vi. Assuming you put the mvim script in /usr/local/bin, this should do it (though you might need sudo, depending on how your Mac is setup):

$ ln -s /usr/local/bin/mvim /usr/local/bin/vi

Let's setup a link for vim too, in case you're ever tempted to run it that way:

$ ln -s /usr/local/bin/mvim /usr/local/bin/vim

We'll also need to tell Bash to clear its cache of where all your programs live, so that it'll search $PATH for vi again and find the new script, instead of the file in /usr/bin/vi:

$ type vi
vi is hashed (/usr/bin/vi)
$ hash -r
$ type vi
vi is /usr/local/bin/vi

If you want to check that you're actually running MacVim, run vi like this:

$ vi --version

You should see "MacOS X (unix) version" in the first couple of lines of output.

Launching the GUI

When you're running MacVim on the console you can switch to the GUI simply by entering :gui from within Vim. It can be quite handy; try help :macvim for more...

I love feedback and questions — please get in touch on Twitter or leave a comment.