FANDOM


Tips related to the Clojure language

How to Comment / Uncomment in Clojure:

The comment leader for Clojure is the ; character. Here's a snippet you can use to comment and uncomment lines in Clojure files

function! ClojureCommentUncomment()
  "search for the ; character at the beginning of the line	
  let search_saved = @/        " save the contents of the search register
  if getline(".") =~ '\;'
    s/^\;//                    " remove the ; at the beginning of the line
  else
    s/^/\;/ "add a ; at the beginning of the line
  endif
  let @/ = search_saved        " restore the contents of the search register
endfunction
map <Leader>. :call ClojureCommentUncomment()<CR>

Typing <Leader>. :help mapleader will now add a ; at the beginning of the current line, if there isn't already one, or remove it, if there is one. 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.

References

Comments

Community content is available under CC-BY-SA unless otherwise noted.