Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Thanks!




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

Search: