Table of Contents

VIM - Config - Indentation - Automatic Indentation Methods

There are a number of methods enabling automatic indentation in VIM, ranging from fairly “stupid” and unintrusive ones, like autoindent and smartindent, to complex ones such as cindent and custom indentation based on filetype using indentexpr.


autoindent

autoindent does nothing more than copy the indentation from the previous line, when starting a new line.


smartindent and cindent

smartindent automatically inserts one extra level of indentation in some cases, and works for C-like files.

cindent is more customizable, but also more strict when it comes to syntax.

WARNING: smartindent and cindent might interfere with file type based indentation, and should never be used in conjunction with it.

When it comes to C and C++, file type based indentations automatically sets cindent, and for that reason, there is no need to set cindent manually for such files.

Generally, smartindent or cindent should only be set manually if you're not satisfied with how file type based indentation works.