Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the single-line comment leader in vim?

Tags:

vim

For vim, the default single-line comment leader is "//". I want to change it to "// " (add a space after //). Should I change comments option? Or is there any other way to make it?

Thanks.

like image 294
Jingguo Yao Avatar asked May 21 '12 05:05

Jingguo Yao


1 Answers

" .vimrc

" It's better to change it only for specific types of files
autocmd FileType c,cpp let b:comment_leader = '// '

" Comment a text block by selecting it in V mode and pressing \cc
noremap <silent> <leader>cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>

" Also
autocmd FileType c,cpp setlocal comments-=:// comments+=b://
like image 82
Panic Avatar answered Sep 30 '22 07:09

Panic