vimauto-indent

Prevent (g)vim from auto-indenting comments


A while ago, I had to put

filetype plugin on

in my .vimrc for a plugin I use.

But this caused a change in autoindent: Whenever I write a comment "//", and then press enter, vim autoindentation automatically enters another "//" in the next line.

// This is a comment. <ENTER>
// <-- vim automatically puts '// ' there

What can I do to avoid this? I use the autoindent setting in my vim file. I already tried

filetype plugin indent off

but it does not work.


Solution

  • Take a look at :h formatoptions and :h fo-table. The options you need to turn off are r and o. Turning them off prevents vim from automatically inserting the comment leader (in this case "//") when you press enter in insert mode or when you press o or O in normal mode.