Hacker News new | past | comments | ask | show | jobs | submit login
How I develop Clojure with Vim (writequit.org)
67 points by swannodette on March 15, 2010 | hide | past | favorite | 30 comments

Using screen to get a REPL alongside vim is pretty clunky. Conque is much easier, in my opinion: http://www.vim.org/scripts/script.php?script_id=2771

I really hope that a real shell gets implemented inside vim at some point, it's almost enough to make one switch to Emacs.

I tried Conque and didn't care for it, refreshing was slow and I favored the detached approach.

I do, however, encourage everyone to try out the different options to find what works for them, what works for me doesn't work for everyone. Conque is a really neat plugin, it's definitely worth a shot for people shopping around.

You can compile one in, but that isn't a great solution - you have to recompile vim on every computer you use it on.

The patch is here: http://www.wana.at/vimshell/

Vim-shell isn't bad, but the version on the site is outdated. You have to scour their mailing list to find a working link to a patch that works with vim 7.2.

Tiling a vim-dow beside a REPL-window in a GUI works for me

:h shell-window

What's the value in rainbow parentheses? I have coded Lisp for years, and have never wondered where I need to add parens; it's intrinsic in the structure of the code. Braces are the same way -- you know when you have the right number. No need for gaudy colors just because nested parentheses are new to you...

You don't need them, but I do find them extremely useful for at a glance parentheses matching, especially if the expressions span multiple lines.

So, the value is as a visual aid - just like any syntax highlighting, highlighting matching parentheses when the cursor is over them, line numbers etc. Non of these things are strictly needed, but they help us comprehend code more easily and quickly.

I just started using Clojure this weekend with Vim. I am not sure why the author of this post didn't use VimClojure with Nailgun, but it works seamlessly and lets you have rich-SLIME like interaction with a REPL.

The only thing I wish I had was a paredit like mode, but you can't have everything!

If you know about vim text objects and f/t motion, there isn't much that paredit mode can do that vim text objects don't. E.g f) is the equivalent to paredit-forward while ci( is 'replace contents of s-expr' and da[ would be 'delete vector'.

I use AutoClose.vim and Surround.vim to deal with most pairwise operations. The only major tweak I make is to rebind s to work as 'surround':

    ""s/S is pretty useless. :help text-objects
    nmap s      <Nop>
    nmap sw     viwS
    nmap sW     viWS
    nmap ss     visS
    nmap sp     vipS
    nmap s[     vi[S
    nmap s]     vi]S
    nmap s(     vi(S
    nmap s)     vi)S
    nmap s{     vi{S
    nmap s}     vi}S
    nmap s<     vi<S
    nmap s>     vi>S
    nmap st     vitS
    nmap s'     vi'S
    nmap s"     vi"S
    nmap s`     vi`S

    nmap S      <Nop>
    nmap Sw     vawS
    nmap SW     vaWS
    nmap Ss     vasS
    nmap Sp     vapS
    nmap S[     va[S
    nmap S]     va]S
    nmap S(     va(S
    nmap S)     va)S
    nmap S{     va{S
    nmap S}     va}S
    nmap S<     va<S
    nmap S>     va>S
    nmap St     vatS
    nmap S'     va'S
    nmap S"     va"S
    nmap S`     va`S
This allows you to do things like wrap the current s-expr in another using S))a.

I also rebind all the vimclojure keys because I hate the defaults (e.g. I use \e to eval, K to lookup docs, and ctrl-] to jump to definition).

Dude! Thank you so much. I was trying to figure out what magic incantation I needed to find the docs for "inner", etc. :help text-objects did the trick and I would have never considered remapping the s/S keys, which are agreeably pretty useless.

EDIT: I created slightly different bindings. These are a bit longer, but have the same power, flexibility, and use of the documented text-object motions.

    " Remap s/S to surround operations
    " :help text-objects
    nmap s      <Nop>
    nmap S      <Nop>
    " Surround inner (si)
    nmap siw     viws
    nmap siW     viWs
    nmap siss    viss
    nmap sip     vips
    nmap si[     vi[s
    nmap si]     vi]s
    nmap si(     vi(s
    nmap si)     vi)s
    nmap si{     vi{s
    nmap si}     vi}s
    nmap si<     vi<s
    nmap si>     vi>s
    nmap sit     vits
    nmap si'     vi's
    nmap si"     vi"s
    nmap si`     vi`s
    " Surround inner on new lines (Si)
    nmap Siw     viwS
    nmap SiW     viWS
    nmap Siss    visS
    nmap Sip     vipS
    nmap Si[     vi[S
    nmap Si]     vi]S
    nmap Si(     vi(S
    nmap Si)     vi)S
    nmap Si{     vi{S
    nmap Si}     vi}S
    nmap Si<     vi<S
    nmap Si>     vi>S
    nmap Sit     vitS
    nmap Si'     vi'S
    nmap Si"     vi"S
    nmap Si`     vi`S
    " Surround an object on same lines (sa)
    nmap saw     vaws
    nmap saW     vaWs
    nmap sas     vass
    nmap sap     vaps
    nmap sa[     va[s
    nmap sa]     va]s
    nmap sa(     va(s
    nmap sa)     va)s
    nmap sa{     va{s
    nmap sa}     va}s
    nmap sa<     va<s
    nmap sa>     va>s
    nmap sat     vats
    nmap sa'     va's
    nmap sa"     va"s
    nmap sa`     va`s
    " Surround an object on new lines (Sa)
    nmap Saw     vawS
    nmap SaW     vaWS
    nmap Sas     vasS
    nmap Sap     vapS
    nmap Sa[     va[S
    nmap Sa]     va]S
    nmap Sa(     va(S
    nmap Sa)     va)S
    nmap Sa{     va{S
    nmap Sa}     va}S
    nmap Sa<     va<S
    nmap Sa>     va>S
    nmap Sat     vatS
    nmap Sa'     va'S
    nmap Sa"     va"S
    nmap Sa`     va`S

Those mappings aren't doing what you expect, because s and S in visual mode do the same thing. And instead of mapping all the text objects like that and using visual mode, you should just do this instead:

    nmap s ys
    nmap S yS

I tested a number of the mapping, they seem to be working. I'm using surround.vim [1] which changes the behavior of s/S in visual mode.

[1] http://www.vim.org/scripts/script.php?script_id=1697

You know, it's not really necessary to use visual mode for those mappings. You could even get away with doing this and it works just the same:

    nmap s ysi
    nmap S ysa


Contrary to popular belief (and my own personal preference ;), you can hack Clojure from Vim, Intellij, Eclipse, and Netbeans (the most full-featured at the moment besides Emacs).

Don't let Emacs stop you. Happy hacking.

Agreed. I see a lot of tweets from people trying to decide on the best editor or IDE for Clojure. Personally, I use Clojure (in all honesty I am just dabbling in it and haven't used it on a full-blown project) but IMO to a large extent - it does not matter.

Use whatever editor you are comfortable with. Learning a new language with an editor getting in your way is pretty hard.

Outside emacs, I agree with swannodette. Enclojure (NetBeans) has the most complete support for Clojure.

For those on Macs, there's a TextMate bundle here:


Works well, though it contains its own clojure install, which may not be ideal. It looks fairly hackable though.

If you do install it, you have to edit a project (folder) in TextMate, otherwise starting the repl will fail. Minor wrinkle.

Development by nullstyle on that stopped in 2008. Clojure wasn't even 1.0 at the time. However looking here, http://github.com/nullstyle/clojure-tmbundle/network, shows that development is alive and kicking, hopefully one of these becomes the new official release.

Upvoted for rainbow parentheses, which I just added to my .emacs =D

Do you mind showing us how? I googled everywhere and only came up with a highlight-parentheses minor mode hack which only highlights the parentheses at the cursor.

Found it... http://dishevelled.net/elisp/rainbow-parens.el

update: Argh! My eyes!

If you're interested in taking things in the opposite direction, try reducing the prominence of parentheses via ParenFace (http://www.emacswiki.org/emacs-en/ParenFace). I use a very light gray face for parentheses, which is barely visible on a white background.

highlight-parentheses minor mode hack which is found here


seems to me like the best solution so far. It only applies "rainbow parens" to the parentheses and parents parentheses of the s-expressions at the cursor.

I tried this mode today and it makes searching and editing terribly slow, even on a relative small file (~700 lines).

I was wondering, and please forgive my ignorance, how do you debug with vi(m) or emacs? They are just text editors, right? Or am I missing something here...

  M-x gdb
Screenshot: http://www.gnu.org/software/emacs/tour/images/gdb.png

If you want to debug a Lisp, you can't do better than Slime. Not sure what the state of the art is on Clojure debuggers.

M-x slime

For a development paltform that's neither brittle nor toy.

Ahh. I see. Does that work in text mode as well?

Vim and emacs are just text editors in the same sense that visual studio, eclipse, netbeans and so forth are just text editors.

Offhand, the only feature I can think of that eclipse has that vim doesn't is the ability to display images and graphs - all the normal editing features (auto completion, code folding, syntax highlighting, integrated debugger, file browser, plugin system, remote editing, integrated repl, multiple editor buffers, compile&run function, etc etc) can be enabled pretty easily. Also, you can run vim and emacs over ssh - cant do that with eclipse or visual studio :)

Really, vim and emacs are full blown IDEs with all the features you'd expect from a modern IDE - except it doesn't use a fancy GUI.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact