2012-05-23 3 views
14

.{cpp,h} 파일의 한 줄 주석 끝에 새 줄을 시작하면 vim이 자동으로 주석을 달아줍니다. 예 :블록 주석에 대해서만 Vim에서 자동 줄 바꿈

// This is a comment<CR> 
// | <- Cursor is moved to `|`, `//` is automatically inserted. 

이것이 플러그인인지 설정인지 확실하지 않습니다. 내 ~/.vimrc에서이 작업을 수행하는 것처럼 보이는 것은 보이지 않으며로드 된 플러그인은 아래에 나열되어 있습니다.

I /* */ 스타일 여러 의견이,하지만 난 내 한 줄 기본적으로 여러 줄에 걸쳐 실행 코멘트를하지 않으있다.

어떤 설정 (또는 플러그인)을 사용합니까?이 주석 유형에만 을 쓸 수 있습니까??

:scriptnames이 있습니다 : {CPP, 시간} 파일, 블록 주석에 영향을주지 않고 //을 위해 트릭을 어떻게해야 당신의 vimrc에서


    1: /Users/simont/.vimrc 
    2: /usr/local/share/vim/vim73/syntax/syntax.vim 
    3: /usr/local/share/vim/vim73/syntax/synload.vim 
    4: /usr/local/share/vim/vim73/syntax/syncolor.vim 
    5: /usr/local/share/vim/vim73/filetype.vim 
    6: /usr/local/share/vim/vim73/ftplugin.vim 
    7: /usr/local/share/vim/vim73/syntax/nosyntax.vim 
    8: /Users/simont/repositories/config-files/vim/colors/solarized.vim 
    9: /usr/local/share/vim/vim73/plugin/getscriptPlugin.vim 
10: /usr/local/share/vim/vim73/plugin/gzip.vim 
11: /usr/local/share/vim/vim73/plugin/matchparen.vim 
12: /usr/local/share/vim/vim73/plugin/netrwPlugin.vim 
13: /usr/local/share/vim/vim73/plugin/rrhelper.vim 
14: /usr/local/share/vim/vim73/plugin/spellfile.vim 
15: /usr/local/share/vim/vim73/plugin/tarPlugin.vim 
16: /usr/local/share/vim/vim73/plugin/tohtml.vim 
17: /usr/local/share/vim/vim73/plugin/vimballPlugin.vim 
18: /usr/local/share/vim/vim73/plugin/zipPlugin.vim 
19: /usr/local/share/vim/vim73/scripts.vim 
20: /usr/local/share/vim/vim73/ftplugin/vim.vim 
21: /usr/local/share/vim/vim73/syntax/vim.vim 

답변

13
au FileType c,cpp setlocal comments-=:// comments+=f:// 

.

현재 버퍼의 사용을 일시적으로 그것을 시도하려면

:setlocal comments-=:// comments+=f:// 
+2

'comments + = f : //'는 무엇을합니까? –

5

이러한 종류의 구성, 그 특정 파일 형식에 관련되어, 일반적으로 파일 타입의 플러그인을 통해 설정됩니다. Vim과 함께 제공되는 일반적인 파일 유형 (예 : .cpp)에 대해 다양한 파일 유형이 있습니다. :set ft?으로 버퍼의 파일 유형을 확인할 수 있습니다.

pb2q가 말한대로 새 줄을 시작한 후 계속되는 주석 설정은 'comments' 옵션에서옵니다. .{cpp,h}의 경우 기본 파일 유형은 'cpp'이고 'comment' 옵션은 cpp.vim이 같은 디렉토리에 있으므로 $VIMRUNTIME/ftplugin/c.vim으로 설정됩니다. c.vim 파일에서 :

" Set 'comments' to format dashed lists in comments. 
    setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// 

comments 옵션은 {flags}:{string}의 목록이며, 플래그 fO 피하기는 주석 신규 라인을 확장. Vim FAQ에서

:

You can use an autocommand triggered on the FileType event: 

     au Filetype * set formatoptions=xyz 

    This should at least be after "filetype on" in your vimrc. Best is to put 
    it in your "myfiletypefile" file, so that it's always last. 


    If you want to override a setting for a particular filetype, then create a 
    file with the same name as the original filetype plugin in the 
    ~/.vim/after/ftplugin directory For example, to override a setting in the 
    c.vim filetype plugin, create a c.vim file in the ~/.vim/after/ftplugin 
    directory and add your preferences in this file. 

그래서 문제를 해결해야

setlocal comments-=:// 
    setlocal comments+=fO:// 

하여 파일 ~/.vim/after/ftplugin/c.vim을 만듭니다.