This question already has an answer here:
-
*
/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim
/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim
39 answers
Answers
http://vim.wikia.com/wiki/Comment_Lines_according_to_a_given_filetype#Related_plugins http://vim.wikia.com/wiki/Comment_Lines_according_to_a_given_filetype#Related_plugins
As a learning experience, attempting a mapping is fine, though. Here s one approach that uses :help map-expr to check the line for the existence of a comment first:
nnoremap <expr> cc getline( . ) =~# ^# ? 0x : 0i#<ESC>
http://learnvimscriptthehardway.stevelosh.com/chapters/05.html http://learnvimscriptthehardway.stevelosh.com/chapters/05.html
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/30625033/vim-comment-uncomment-with-one-mapping