

How I develop Clojure with Vim - swannodette
http://writequit.org/blog/?p=386

======
jcw
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.

~~~
mhansen
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/>

~~~
jcw
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.

------
jrockway
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...

~~~
dkersten
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.

------
gfodor
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!

~~~
grayrest
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).

~~~
snprbob86
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

~~~
graywh
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

~~~
snprbob86
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>

------
swannodette
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.

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

[http://nullstyle.com/2008/11/09/ann-clojure-textmate-
bundle-...](http://nullstyle.com/2008/11/09/ann-clojure-textmate-bundle-01/)

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.

~~~
swannodette
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.

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

~~~
twism
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.

~~~
twism
Found it... <http://dishevelled.net/elisp/rainbow-parens.el>

update: Argh! My eyes!

~~~
avigesaa
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.

~~~
twism
highlight-parentheses minor mode hack which is found here

[http://stackoverflow.com/questions/2413047/can-emacs-
color-d...](http://stackoverflow.com/questions/2413047/can-emacs-color-
different-levels-of-matching-parentheses-with-a-rainbow-of-differ)

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.

------
pan69
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...

~~~
tsally

      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.

~~~
mahmud
M-x slime

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

