2012-05-23 25 views
14

जब मैं .{cpp,h} फ़ाइल में एकल-पंक्ति टिप्पणी के अंत में एक नई पंक्ति शुरू करता हूं, vim स्वचालित रूप से टिप्पणी कर रहा है। उदाहरण के लिए:ब्लॉक टिप्पणियों के लिए केवल Vim में नई पंक्ति ऑटो-टिप्पणी

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

मुझे यकीन नहीं है कि यह एक प्लगइन या सेटिंग है या नहीं। मैं ऐसा कुछ नहीं देख सकता जो ऐसा लगता है कि यह मेरे ~/.vimrc में ऐसा करेगा, और लोड किए गए प्लगइन नीचे सूचीबद्ध हैं।

मैं /* */ शैली बहु टिप्पणी के लिए इस, लेकिन मैं अपने एकल लाइन टिप्पणियां डिफ़ॉल्ट रूप से कई पंक्तियों पर चल नहीं चाहते हैं की तरह।

कौन सी सेटिंग (या प्लगइन) यह करता है, और क्या मैं इसे से बंद कर सकता हूं इस टिप्पणी के लिए केवल?

:scriptnames इस देता है:


    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:// 

अपने vimrc ब्लॉक टिप्पणियों को प्रभावित करने, {सीपीपी, ज} फाइलों में बिना // के लिए चाल करना चाहिए में।

वर्तमान बफर उपयोग में अस्थायी रूप से यह कोशिश करने के लिए:

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

'टिप्पणियां + = f: // 'क्या करती है? –

5

विन्यास इस तरह कि विशिष्ट फ़ाइल प्रकार से संबंधित है, आम तौर पर एक फ़ाइल प्रकार प्लगइन के माध्यम से स्थापित कर रहे हैं। सामान्य फ़ाइल प्रकारों (जैसे .cpp) के लिए कई फ़ाइल-प्रकार हैं जो विम के साथ आता है। आप :set ft? के साथ एक बफर के लिए फ़ाइल-प्रकार की जांच कर सकते हैं।

एक नई लाइन शुरू करने के बाद टिप्पणियां जारी रखने की सेटिंग विकल्प 'comments' से आता है, जैसा कि pb2q ने कहा था। .{cpp,h} के लिए डिफ़ॉल्ट फ़ाइल-प्रकार 'cpp' है, और 'comment' विकल्प $VIMRUNTIME/ftplugin/c.vim पर सेट किया गया है, क्योंकि cpp.vim एक ही निर्देशिका में है। c.vim फ़ाइल से:

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

comments विकल्प {flags}:{string} की एक सूची है, और झंडे f और O बचने टिप्पणी नई लाइनों का विस्तार।

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 बनाने समस्या का समाधान करना चाहिए।