Wednesday, June 10, 2009

Vim OS X Clojure Syntax Highlighting

A lot of people seem to have had trouble with this; the creator of vimclojure said he got it running with no problems on his OS X box with the default vim 7.2.2 install, but so many other people have had problems with it that he recommends using MacVim instead. I don't enjoy MacVim as much as regular old command-line vim, so I set about getting it working on my box.

It seemed at first like a lot of effort, but in fact it was easy. First, download vimclojure. Next install some files, and edit your machine's main vimrc.

Your vimrc should look something like this:

Actually, that's not quite right. The line that says filetype plugin on should say filetype plugin indent on. Anyway, you can get all this from the vimclojure documentation - the one piece that's missing is the final line:

au BufRead,BufNewFile *.clj set filetype=clojure

That's the line that tells vim that *.clj files are Clojure files.

I got interested to solve this problem after skimming Matt Sears' Clojure links roundup. Check it out for more Clojure info. There are syntax highlighters for other editors as well. One last bonus tidbit, setting expandtab and tabstop=2 allows you to use spaces instead of tabs, just like in TextMate.