Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #1361 - Disable automatic comment insertion

Created: October 18, 2006 0:57 Complexity: basic Author: Johnny Version: 5.7 Karma: 170/47 Imported from: Tip#1361

Auto-comment is a good idea for vim, but some times you may like to disable it. I get trouble in this for a few days, and finally I found how to disable this function. For c/cpp file, just locate to the $VIMRUNTIME\ftplugin\c.vim

Find the line

setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// 

change it into

setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,f:// 

then the // comment will not auto repeat in the next line. the key for this is the "f" flag.

References

Comments

There is no need to edit the ftplugin file itself, just define an auto command which gets executed whenever a c/c++ file is opened.
Put the following line in your .vimrc:

au FileType c,cpp setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,f:// 

Anonymous , October 19, 2006 1:18


Or use

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

Anonymous , October 19, 2006 3:05


TODO: fix the tip because editing a standard ftplugin is a very bad idea.
The solution consists in either providing a custom autocommand, or even better in overriding this setting in end-user defined c-ftplugin.

--Luc Hermitte 11:52, 16 August 2007 (UTC)


Advertisement