CentOS 7.x Disabling auto-comment of next line in vim

From Notes_Wiki

Home > CentOS > CentOS 7.x > Desktop tools or applications > CentOS 7.x editor configuration > CentOS 7.x vim > CentOS 7.x 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


Disabling auto-indent in vim

If the above technique is not working for disabling auto-indentation then use:

:setl noai nocin nosi inde=

which is shortform of:

   :set noautoindent
   :set nocindent
   :set nosmartindent
   :set indentexpr=

Steps learned from http://vim.wikia.com/wiki/How_to_stop_auto_indenting


Home > CentOS > CentOS 7.x > Desktop tools or applications > CentOS 7.x editor configuration > CentOS 7.x vim > CentOS 7.x Disabling auto-comment of next line in vim