
A função a seguir ~/.vimrc
é comentar a linha C e funciona perfeitamente.
function CLC()
execute "normal ^i/*\<ESC>$a*/\<ESC>"
endfunction
Mas tenho duas perguntas...
1. Como faço para comentar umfaixade linhas.
2. Como posso comentá-los assim:
/*
* multiline
* comment
*
*/
Estou ciente do plugin NERDCommenter que faria as duas coisas para mim, mas um dos mapeamentos entra em conflito com o mapeamento de outro plugin que possuo.
Responder1
:help NERDComMappings
explica como alterar os mapeamentos padrão do NERDCommenter. Por exemplo, coloque isso em seu ~/.vimrc
para alterar o prefixo de mapeamento para <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
Responder2
Modo de comentários sexy C
Os intervalos de linhas funcionam por padrão com seleção visual + <leader>cc
, testado em 2.5.2.
Mas acima de tudo, quero destacar nesta resposta os comentários do "modo sexy" com <leader>cs
, que geram belos comentários multilinhas em C.
Por exemplo, se você começar com:
This is a c style sexy comment
So there!
então, <leader>cs
a partir da seleção visual, transforma-o em:
/* This is a c style sexy comment
* So there! */
E você também pode mudar para o modo não compacto adicionando ao seu .vimrc
:
let g:NERDCompactSexyComs = 0
que funciona da seguinte maneira:
------------------------------------------------------------------------------
*'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
*/
Outro formato relacionado que pode ser de interesse é o "Mapa de comentários mínimos" acessível <leader>cm
e que produz:
/* Hi There!
This is a sexy comment
in C */
Infelizmente, não consegui encontrar meu estilo preferido:
/* Hi There!
* This is a sexy comment
* in c
*/
então eu abri:https://github.com/scrooloose/nerdcommenter/issues/379