Vim C 라인 주석 기능

Vim C 라인 주석 기능

다음 기능은 ~/.vimrcC 라인을 주석 처리하는 것이며 완벽하게 작동합니다.

function CLC()
    execute "normal ^i/*\<ESC>$a*/\<ESC>"
endfunction

그런데 두 가지 질문이 있습니다...
1. 주석 처리를 어떻게 합니까?범위라인.
2. 어떻게 하면 다음과 같이 주석 처리할 수 있습니까?

/*  
 * multiline   
 * comment   
 *   
 */

나는 이 두 가지를 모두 수행하는 NERDCommenter 플러그인을 알고 있지만 매핑 중 하나가 내가 가지고 있는 다른 플러그인에 대한 매핑과 충돌합니다.

답변1

:help NERDComMappingsNERDCommenter의 기본 매핑을 변경하는 방법을 알려줍니다. 예를 들어 ~/.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>cc2.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

관련 정보