1

I might not have discovered everything about it, but the smartindent option has given me much more trouble than usefulness. For example, it indents a line beginning with for or if, and won't shift a line beginning with #. Probably I'm wrong having this option on when editing normal text files (not programs). But I'm wondering where this option can ever be useful, given the fact that you have cindent for C programs and various plugins for other specific languages.

1

Here is an example typing the following into vim --clean, with each option set:

hello {
world
foo;
bar
}

smartindent only:

hello {
    world
    foo;
    bar
}

cindent only:

hello {
    world
        foo;
    bar
}

As you can see with cindent, vim tries to continue lines that are incomplete (i.e., without semicolon). If your language is c-like, this behavior is smart. On the other hand, if your language uses braces but no semicolons, this would be undesirable.

Note that cindent has many more options via cinoptions and can be configured to suit many languages. This example demonstrates just the default behavior with no additional configuration.

0

According to :help 'smartindent':

Do smart autoindenting when starting a new line. Works for C-like programs, but can also be used for other languages. 'cindent' does something like this, works better in most cases, but is more strict, see |C-indenting|. When 'cindent' is on or 'indentexpr' is set, setting 'si' has no effect. 'indentexpr' is a more advanced alternative.

Thus, there are several options that work in the same context. I suspect that this is primarily for historical reasons. Vim tries very hard not to break backwards compatibility. Thus, if a setting is improved in a way that might break things, the Vim way is to introduce a new setting. Perhaps some users prefer the old way. Thus, judging from the documentation, it appears that smartindent is an earlier approach to indenting C-like code.

Finally, the documented behavior tells us that it's specifically aimed at C and similar languages. Thus, it's to be expected that it would cause problems in plain text files, Python, Javascript, etc. Better to set it in a filetype autocommand if you want it. Personally, I find that :set autoindent meets my needs just fine, since I never write C code.

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.