2012-05-23 37 views
14

Khi tôi bắt đầu một dòng mới ở cuối một nhận xét một dòng trong một tệp .{cpp,h}, vim sẽ tự động nhận xét nó. Ví dụ:Tự động nhận xét dòng mới trong Vim chỉ cho các nhận xét khối

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

Tôi không chắc đây có phải là plugin hay cài đặt hay không. Tôi không thể nhìn thấy bất cứ điều gì có vẻ như nó sẽ làm điều này trong ~/.vimrc của tôi, và các plugin được tải được liệt kê dưới đây.

tôi như này cho /* */ kiểu multiline ý kiến, nhưng tôi không muốn tôi single-line comments chạy trên nhiều dòng bằng cách mặc định.

Cài đặt (hoặc plugin nào) thực hiện việc này và tôi có thể tắt chế độ này cho loại nhận xét này chỉ?

:scriptnames cho này:


    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 

Trả lời

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

Trong vimrc của bạn nên làm các trick cho // mà không ảnh hưởng khối kiến, trong {cpp, h} tập tin.

Để thử nó tạm thời trong việc sử dụng bộ đệm hiện tại:

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

'comments + = f: //' làm gì? –

5

Đây là loại cấu hình, có liên quan đến các loại tập tin cụ thể, thường được thiết lập thông qua một plugin của loại tập tin. Có một số loại tệp cho các loại tệp phổ biến (chẳng hạn như .cpp) đi kèm với Vim. Bạn có thể kiểm tra loại tệp cho bộ đệm với :set ft?.

Cài đặt để tiếp tục nhận xét sau khi bạn bắt đầu một dòng mới đến từ tùy chọn 'comments', như pb2q đã nói. Đối với .{cpp,h} loại tệp mặc định là 'cpp' và tùy chọn 'comment' được đặt tại $VIMRUNTIME/ftplugin/c.vim, vì cpp.vim nằm trong cùng một thư mục. Từ c.vim file:

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

Tùy chọn comments là danh sách các {flags}:{string}, và cờ fO tránh mở rộng các dòng bình luận mới.

Từ 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. 

Vì vậy, tạo ra các tập tin ~/.vim/after/ftplugin/c.vim với

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

nên giải quyết vấn đề.

Các vấn đề liên quan