
下面的函數~/.vimrc
是註解掉C行,並且運行得很好。
function CLC()
execute "normal ^i/*\<ESC>$a*/\<ESC>"
endfunction
但我有兩個問題...
1.我要如何讓它註解掉範圍的線路。
2.我怎樣才能像這樣註解掉它們:
/*
* multiline
* comment
*
*/
我知道 NERDCommenter 插件可以為我完成這兩個任務,但其中一個映射與我擁有的另一個插件的映射衝突。
答案1
:help NERDComMappings
告訴您如何變更 NERDCommenter 的預設映射。例如,將其放入您的中~/.vimrc
以將映射前綴更改為<Leader>C
:
nmap <Leader>Cc <Plug>NERDCommenterComment
xmap <Leader>Cc <Plug>NERDCommenterComment
nmap <Leader>C<Space> <Plug>NERDCommenterToggle
xmap <Leader>C<Space> <Plug>NERDCommenterToggle
nmap <Leader>Cm <Plug>NERDCommenterMinimal
xmap <Leader>Cm <Plug>NERDCommenterMinimal
nmap <Leader>Cs <Plug>NERDCommenterSexy
xmap <Leader>Cs <Plug>NERDCommenterSexy
nmap <Leader>Ci <Plug>NERDCommenterInvert
xmap <Leader>Ci <Plug>NERDCommenterInvert
nmap <Leader>Cy <Plug>NERDCommenterYank
xmap <Leader>Cy <Plug>NERDCommenterYank
nmap <Leader>Cl <Plug>NERDCommenterAlignLeft
xmap <Leader>Cl <Plug>NERDCommenterAlignLeft
nmap <Leader>Cb <Plug>NERDCommenterAlignBoth
xmap <Leader>Cb <Plug>NERDCommenterAlignBoth
nmap <Leader>Cn <Plug>NERDCommenterNest
xmap <Leader>Cn <Plug>NERDCommenterNest
nmap <Leader>Cu <Plug>NERDCommenterUncomment
xmap <Leader>Cu <Plug>NERDCommenterUncomment
nmap <Leader>C$ <Plug>NERDCommenterToEOL
xmap <Leader>C$ <Plug>NERDCommenterToEOL
nmap <Leader>CA <Plug>NERDCommenterAppend
xmap <Leader>CA <Plug>NERDCommenterAppend
nmap <Leader>ca <Plug>NERDCommenterAltDelims
答案2
性感C評論模式
預設情況下,行範圍僅適用於視覺選擇 + <leader>cc
,在 2.5.2 上進行了測試。
但最重要的是,我想在這個答案中強調「性感模式」註釋<leader>cs
,它會產生漂亮的 C 多行註釋。
例如,如果您從以下內容開始:
This is a c style sexy comment
So there!
然後<leader>cs
從視覺選擇將其轉換為:
/* This is a c style sexy comment
* So there! */
您也可以透過新增以下內容來切換到非緊湊模式.vimrc
:
let g:NERDCompactSexyComs = 0
其工作原理如下:
------------------------------------------------------------------------------
*'NERDCompactSexyComs'*
Values: 0 or 1.
Default 0.
Some people may want their sexy comments to be like this: >
/* Hi There!
* This is a sexy comment
* in c */
<
As opposed to like this: >
/*
* Hi There!
* This is a sexy comment
* in c
*/
另一種可能感興趣的相關格式是“最小評論地圖”,可通過<leader>cm
和 訪問,它會產生:
/* Hi There!
This is a sexy comment
in C */
不幸的是我沒能找到我喜歡的風格:
/* Hi There!
* This is a sexy comment
* in c
*/
所以我打開:https://github.com/scrooloose/nerdcommenter/issues/379