Vim Tips Wiki
m (Disable auto-comment when editting c/cpp files moved to Disable auto-comment when editing C/Cpp files: Page moved by JohnBot to improve title)
No edit summary
Line 47: Line 47:
 
[[Category:C]]
 
[[Category:C]]
 
[[Category:C plus plus]]
 
[[Category:C plus plus]]
  +
  +
This has been annoying me for a while as well:
  +
  +
:set fo=cql
  +
  +
That takes the ro out of the formatoptions.
  +
  +
a :set fo-=ro (could work, I didn't get it working though)

Revision as of 02:05, 22 October 2007

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)


This has been annoying me for a while as well:

set fo=cql

That takes the ro out of the formatoptions.

a :set fo-=ro (could work, I didn't get it working though)