58

I read the wiki entry on vim source code indentation

I still can't understand the difference between autoindent and smartindent

It seems they do the same thing, copy the indentation level to next line when you press enter.

2
  • 7
    The wiki is very close to useless. Read :help autoindent and :help smartindent.
    – romainl
    Dec 14, 2015 at 8:54
  • the wiki actually has a pretty decent explanation of your options: vim.wikia.com/wiki/…
    – ian5v
    Sep 16, 2016 at 4:20

1 Answer 1

48

autoindent essentially tells vim to apply the indentation of the current line to the next (created by pressing enter in insert mode or with O or o in normal mode.

smartindent reacts to the syntax/style of the code you are editing (especially for C). When having it on you also should have autoindent on.

:help autoindent also mentions two alternative settings: cindent and indentexpr, both of which make vim ignore the value of smartindent.

2
  • 3
    The answer above is correct. The Only thing you need to do extra to enable this while using vim or in the .vimrc is to use set command in the beginning. i.e. set autoindent
    – m33k
    Sep 8, 2021 at 21:29
  • Welcome to Vi and Vim, @m33k! I turned your post into a comment, since it was clearly referring to this answer. Cheers!
    – filbranden
    Sep 8, 2021 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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