Writing Clojure with Vim

If you want to do Clojure development with vim, the key things you need are the fantastic Fireplace.vim from dear, dear tpope along with Paredit. A great getting started post by Gabe Hollombe is here. It mostly mirrors my current setup.

Getting started with Paredit for writing Clojure

You won’t have the full power of editing Clojure in vim without using paredit. When you first start using it, you will feel like you’re swimming in a vat of Jello. It is a very difficult initial transition. Once you get the hang of it, though, it is like having a superpower.

Here’s the key to getting started: knowing how to disable paredit mode from within the editor. Here’s the secret: in vim command mode, type:

:call PareditToggle()

That turns off paredit mode. To turn it back on, type that command again. Paredit forces you to balance parens () and all matching characters such as “”, [], et al. That is what is great about it, but it is very disorienting when you are just getting started. You will want to quickly move to having paredit enabled at all times, as that is how you will become proficient with it. For those first few sessions with it, though, being able to turn it off will probably make the difference between loving and hating it.

You can also toggle paredit across all sessions by adding this to your .vimrc (0=off, 1= on):

let g:paredit_mode=0

Here’s the other key to paredit: map your leader. The leader is supposed to be mapped to , in paredit by default, but, for whatever reason, it was not for me. So I added this to my .vimrc:

1 comment

Paredit… Maybe it’s just me, but I’m no lisp compiler. I don’t have to be fed, or think in terms of, complete lisp forms.
I mostly deal in fragments. Only when I send my file off to the compiler, I want the parens to be balanced.
The rest of the time it’s more of a nuisance and I can’t understand why someone would voluntarily limit themselves to such mode of communication with your editor.
So instead of “You won’t have the full power of editing Clojure in vim without using paredit”, let’s be frank and recognize that paredit LIMITS you (with “good” intent, but nevertheless). You will have the FULL power of editing clojure IN VIM only without using paredit.