How to change single line comment leader in vim?

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

Thank.

+3
source share
1 answer
" .vimrc

" It 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://
+6
source

All Articles