Mohammed H
Mohammed H

Reputation: 7048

autoindent is subset of smartindent in vim?

: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?

Upvotes: 29

Views: 13742

Answers (1)

romainl
romainl

Reputation: 196506

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.

Upvotes: 57

Related Questions