Clojure Tips

From Vim Tips Wiki

Jump to: navigation, search
Tip 1631 Printable Monobook Previous Next

created 2009 · complexity basic · version 7.0


Tips relating to the Clojure language will be given here.

[edit] Commenting and uncommenting

The comment leader for Clojure is the ; character. This snippet allows easy commenting and uncommenting of lines.

map <Leader>. :call ClojureCommentUncomment()<CR>
function! ClojureCommentUncomment()
  let search_saved = @/
  if getline('.') =~ '^;'
    s/^;//  " remove ';' at beginning of line
  else
    s/^/;/  " insert ';' at beginning of line
  endif
  let @/ = search_saved
endfunction

Typing \. (assuming the default backslash leader) will remove ; from the beginning of the current line if it is present (uncomment), or will insert it otherwise (comment). You could make this more restrictive by only adding the mapping for files of the Clojure filetype, or by adding it to ~/.vim/after/ftplugin/clojure.vim.

[edit] References

[edit] Comments

 TO DO 

  • May need some information similar to VimTip1565 for making Clojure a known filetype.
  • The tip used '\;' but the backslash is redundant (I removed it).
  • The tip had if getline('.') =~ '\;' but s/^;//. The former matches ; anywhere in the line, while the latter only matches at the left margin. I changed it.

Please fix it if my changes broke anything. JohnBeckett 10:25, September 5, 2009 (UTC)

Personal tools