57

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.

StandardEyre
  • 1,118
  • 1
  • 10
  • 22
Aaron Shen
  • 2,519
  • 3
  • 24
  • 37
  • 7
    The wiki is very close to useless. Read :help autoindent and :help smartindent. – romainl Dec 14 '15 at 08:54
  • the wiki actually has a pretty decent explanation of your options: http://vim.wikia.com/wiki/Indenting_source_code#Methods_for_automatic_indentation – ian5v Sep 16 '16 at 04:20

1 Answers1

47

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.

guntbert
  • 1,245
  • 1
  • 13
  • 27
  • 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 08 '21 at 21:29
  • Welcome to [vi.se], @m33k! I turned your post into a comment, since it was clearly referring to this answer. Cheers! – filbranden Sep 08 '21 at 21:51