Vim – Stop Vim from Messing Up Indentation on Comments

vivim

For some reason Vim thinks all of my comments should have all indentation removed. If I add # to the beginning of a line, suddenly all leading whitespace is removed. How can I stop this?

I have Janus and NERDtree installed, in case it's relevent, along with copious other personal configurations in my .vimrc, but none that (as far as I know) would cause such behavior.

Best Answer

I'm never satisfied with the "set all these things just in case" answers. I insist on knowing which of those things were set wrong and how they got set. Here is a command that will show you the values of all the relevant settings mentioned here, as well as where they were last set. If no Last set from line follows, it is a default value. No point in re-setting correct default values.

:verbose set autoindent? smartindent? cindent? cinkeys? indentexpr?

noautoindent
nosmartindent
  cindent
        Last set from ~/.vim/vimrc
  cinkeys=0{,0},0),:,!^F,o,O,e
        Last set from ~/.vim/vimrc
  indentexpr=
Press ENTER or type command to continue

See: http://vimdoc.sourceforge.net/htmldoc/options.html#:set-verbose

All I had to do to get that working was remove set smartindent from a plugin and add to my ~/.vim/vimrc:

set cindent cinkeys-=0#
set expandtab shiftwidth=4 tabstop=4 softtabstop=4
Related Question