Mapped commenting

Crazy simple, just maps F5 to comment and F6 to uncomment based on the filetype. This requires the Filetype plugin to be enabled (default in 7.2). The replace is non-destructive of leading whitespace, feel free to remove it if you wish.

Note: Multiline commenting style ie., /**/ is unsupported, however, using the mapping in visual mode with text selected will apply/remove comments to the entire selection

Another Note: To get around accidently copying html entities just click the download button, put the file in ~/.vim/after and add the following to your .vimrc file (this also allows you to easily disable it if you don't like it

source ~/.vim/after/mapped-commenting.vim

Plain" perl style # commenting autocmd FileType php,yaml noremap <F5> :s/\v^(\s*)/\1#/ <CR> autocmd FileType php,yaml noremap <F6> :s/\v^(\s*)#/\1/ <CR> " C style // commenting autocmd FileType c,cpp,php noremap <F5> :s+\v^(\s*)+\1//+ <CR> autocmd FileType c,cpp,php noremap <F6> :s+\v^(\s*)//+\1+ <CR> " vim commenting autocmd FileType vim noremap <F5> :s/\v^(\s*)/\1"/ <CR> autocmd FileType vim noremap <F6> :s/\v^(\s*)"/\1/ <CR>
Add Comment