General Indentation Settings:set autoindent
If set, Vim automatically indents a new line to the same indentation used by previous line. In other words ViM automatically tabs a new line. smartindent and cindent are autoindent variations and changes the way indentation and formatting more precisely.
Context-sensitive autoindent, great when coding, makes intendation aware of C-like syntax.
Using this option you can define number of spaces placed on every indentation step i.e. :set shiftwidth=3 will instruct Vim to indent with 3 spaces for every TAB command.
TAB Settings:set expandtab
Use this option if you want every TAB to be expanded to spaces.
If this option is set, then TAB command shifts line to right and BACKSPACE shifts line to left, both inserting number of blanks as defined in shiftwidth. If smarttab is not set, then TAB inserts blanks according to tabstop.
This one tells Vim to interpret TAB as an indent command instead of insert-a-TAB command.
Simply, it instructs Vim how many space characters Vim counts for every TAB command. According to Vim manual it’s recommended to leave default tabstop=8, what means every TAB is displayed with 8 space characters, and adjust only softtabstop and shiftwidth.
C-style Indent:set cindent
This sets autoindent to even more smart and strict mode for C and C++ source code.
Simply, it sets cindent configuration options.
HelpTo learn how to use Vim commands and how to set indentation settings refer to online VimDoc or run open help :h where option is one of Vim command. I also recommend to take a look at the Vim website with documentation and huge database of tips.
Online ResourcesVi and Vim in Linux Productivity Magazine, Volume 1 Issue 5
Introduction to Programming in C/C++ with Vim by Kmj
VIM (Vi IMproved)
The Vi/Ex Editor by Walter Alan Zintz
Vi for programmers, part 1 and part 2