3

From :h indent.txt:

...each one overrides the previous if it is enabled...

Now if I set 'cin' after 'ai', Does 'cin' disable the effect of 'ai'?.
If no, so what is the purpose of "override" exactly?

2

Order does not matter. The override behavior is based on what is currently set/unset, changing one option value does not change others. Additionally, indent.txt refers to methods not settings, so the behavior is not completely straight-forward since the expression in indentexpr can itself return "not enabled." The documentation requires some further explanation:

  1. If indentexpr is set, cindent,smartindent, and autoindent will all have no base effect (* caveat 1 applies). Note that for indentexpr "unset" means set to empty string.
  2. If cindent is set and indentexpr is unset, {smartindent,autoindent} will have no effect.
  3. If smartindent is set and {cindent, indentexpr} are unset, autoindent will have no effect (* caveat 2 applies).
  4. Finally, if {cindent, indentexpr, smartindent} are unset autoindent takes effect.

(* caveat 1 ) If indentexpr returns -1, vim specifies that the value of autoindent is used. So, if smartindent or cindent is on, and autoindent is off, and the indentexpr evaluates to -1, indenting will not take place, which is potentially unexpected.

(* caveat 2 ) The documentation is misleading here. You should set autoindent if you have smartindent for reasons that are unclear (besides perhaps the reason given in (* caveat 1) above). From :h smartindent:

Normally 'autoindent' should also be on when using 'smartindent'.

The bottom line is you should always set "lesser" indent methods when using "greater" ones, although it sometimes doesn't matter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.