:help autoindent : Copy indent from current line when starting a new line (typing in Insert mode or when using the "o" or "O" command). ...
:help smartindent : Do smart autoindenting when starting a new line. Works for C-like programs, but can also be used for other languages. ...
Normally 'autoindent' should also be on when using 'smartindent'. An indent is automatically inserted:
- After a line ending in '{'.
- After a line starting with a keyword from 'cinwords'.
Before a line starting with '}' (only with the "O" command).
When typing '}' as the first character in a new line, that line is given the same indent as the matching '{'. ...
smartindent also coping indent from current line when starting a new line. That means autoindent feature is subset of smartindent feature and no need of autoindent if smartindent is on, right? Why autoindent should be turn on?
Vim has four methods of indentation, namely: Autoindent – this method uses indent from the previous line for the file type you are editing. smartindent – smartindent works similarly to autoindent but recognizes the syntax for some languages such as C language.
vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.
smartindent
is an old script that was meant, when it was written, to be a "smart" complement to autoindent
. Since then, most languages have either specific indentation functions or use cindent
with specific options.
Generally, smartindent
shouldn't be used at all.
The following lines are usually enough to deal with indentation:
set autoindent filetype plugin indent on
autoindent
is not strictly necessary but it's good to have it when working with plaintext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With