如何更改vim中的单行评论领导者?

时间:2012-05-21 05:45:09

标签: vim

对于vim,默认的单行评论标题是“//”。我想将其更改为“//”(在//之后添加一个空格)。我应该更改评论选项吗?或者还有其他方法可以做到吗?

感谢。

1 个答案:

答案 0 :(得分:7)

" .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://