- You're correct that
smartindent
and autoindent
should do what you want, but it might be overruled by the archaic compatible
setting.
Be sure you're not in vi compatible mode. You want set compatible?
to return nocompatible
. This means that Vim will not be backwards compatible to the old vi program. In older Vim versions, it started up in compatible
mode by default and left it to the users' .vimrc files to include set nocompatible
.
Newer versions of Vim will automatically start up in nocompatible
mode, which is what you want.
- Many common file extensions will get the
filetype
setting assigned. If :filetype
returns detection: ON
and indent:ON
, then the filetype indentation might be setting the indentexpr
to a function which should be better than smartindent
, but maybe it's worse. What is your filetype?
If you're writing Javascript, then the filetype should be javascript
. If filetype detection and indentation is on, then the indentexpr
should be GetJavaScriptIndent()
which will do exactly what you want.
I usually recommend not using autoindent
and smartindent
and instead use filetype indentation.
In summary, these two lines in a ~/.vimrc should help out:
set nocompatible
filetype plugin indent on
:set filetype?
'smartindent'
should do this, so it sounds like your setting may be overridden by something else in your config. What is the output of the command:verbose set si? inde?