User Tools

Site Tools


vim:config:indentation:automatic_indentation_methods

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.

  • The amount of indentation used for one level is controlled by the shiftwidth option. (See above.)

autoindent

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

  • It can be useful for structured text files, or when you want to control most of the indentation manually, without VIM interfering.
  • autoindent does not interfere with other indentation settings, and some file type based indentation scripts even enable it automatically.

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.

  • In these cases, the cinwords, cinkeys and cinoptions options still apply.

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

vim/config/indentation/automatic_indentation_methods.txt · Last modified: 2022/10/08 14:29 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki