Disabling auto-comment of next line in vim

From Notes_Wiki
Revision as of 01:24, 1 January 2013 by Saurabh (talk | contribs) (Created page with "<yambe:breadcrumb>Vim|Vim</yambe:breadcrumb> =Disabling auto-comment of next line in vim= Sometimes while editing a known file type with vim it automatically continues the co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<yambe:breadcrumb>Vim|Vim</yambe:breadcrumb>

Disabling auto-comment of next line in vim

Sometimes while editing a known file type with vim it automatically continues the comment on next line. For example if one has line '//abc' in a C file then pressing return key at the end of this line would cause next line to automatically have comment characters '//'. The same is applicable while editing .emacs file with vim where comments begin with ';'.

Now if we copy paste some C program lines or .emacs configuration lines from other location into the current file then this automatic extension of comment causes problem as all lines after first comment line get commented while pasting. Thus to disable this auto-comment feature while pasting lines from other source one can modify formatoptions variable.

To see current value of formatoptions variable use:

:set formatoptions?

To disable auto-comment extension by modifying formatoptions use:

setlocal formatoptions-=c formatoptions-=r formatoptions-=o


To disable comment extension permanently for few types of files one can use following configuration in .vimrc file:

autocmd FileType c,cpp setlocal formatoptions-=c formatoptions-=r formatoptions-=o


Steps have been learned from http://vim.wikia.com/wiki/Disable_automatic_comment_insertion


<yambe:breadcrumb>Vim|Vim</yambe:breadcrumb>