Disable auto-comment when editing C/C++ files
From Vim Tips Wiki
Tip 1361 Previous Tip • Next Tip
Created: October 18, 2006 Complexity: basic Author: Johnny Minimum version: 5.7 Karma: 170/47 Imported from: Tip#1361
Auto-comment is a good idea for Vim, but sometimes you may like to disable it. For c/cpp files, just locate file $VIMRUNTIME\ftplugin\c.vim
Find the line
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
change it to
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.
[edit] References
TO DO
- Fix this 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.
[edit] 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://
Or use:
setlocal comments-=:// setlocal comments+-f://
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)
I saw The following block in the c.vim, right next to the lines mentioned in the original comment. commenting off this one worked perfectly fine.
" Set 'formatoptions' to break comment lines but not other lines, " and insert the comment leader when hitting <CR> or using "o". setlocal fo-=t fo+=croql
changed to
" Set 'formatoptions' to break comment lines but not other lines, " and insert the comment leader when hitting <CR> or using "o". " setlocal fo-=t fo+=croql
