Setting up Vim for Clojure
I’ve been experimenting with Clojure lately. A few of my coworkers had begun the discovery process as well, so I suggested that we have a weekly show-and-tell, because a little accountability and audience can turn wishes into action.
Naturally, I looked around for plug-ins that would be of use in my editor of choice. Here’s what I have installed:
- vim-clojure-static - Syntax highlighting and indentation
- vim-fireplace - Slick repl integration and hot code reload
- rainbow_parentheses.vim - Pretty rainbow coloring for ease of matching parentheses
- vim-sexp - A whole host of ways to edit S-expressions, some of which I’m sure I’ll understand more as I get further in
- vim-sexp-mappings-for-regular-people - Tim Pope’s riff on the above, minus the meta key
These are all straightforward to install, as long as you already have a Pathogen or Vundle setup going. If you don’t, you really should, because nobody likes a messy Vim install.
All of these plug-ins automatically work when a Clojure file is opened, with the exception of rainbow parentheses. To enable those, a little .vimrc config is necessary:
au BufEnter *.clj RainbowParenthesesActivate au Syntax clojure RainbowParenthesesLoadRound au Syntax clojure RainbowParenthesesLoadSquare au Syntax clojure RainbowParenthesesLoadBraces
Now, once that’s all set up, it’s time to show a little bit of what this setup can do. I have a little clojure test app over here on github. After cloning it (and assuming you’ve already installed leiningen):
- Open up dev.clj and follow the instructions to set up the application in a running repl.
- Then open testclj/core.clj and make any modification, such as changing “Hello” to “Hi”.
- Then after a quick
cprto reload the namespace in the repl, you can reload your web browser to see the updated code.
This setup makes for a quick dev/test cycle, which is quite useful for experimentation. Of course, there are many more features of each of the above plugins. I’ve barely scratched the surface and I’m already very impressed.