Use :set expandtab
.
This will expand all tabs to spaces, during insert, even the ones at the beginning of the line (which probably is the best).
Use CTRL-V<Tab>
to insert a tab.
From vim
help (:help expandtab
)
'expandtab' 'et' boolean (default off)
local to buffer
{not in Vi}
In Insert mode: Use the appropriate number of spaces to insert a
<Tab>. Spaces are used in indents with the '>' and '<' commands and
when 'autoindent' is on. To insert a real tab when 'expandtab' is
on, use CTRL-V<Tab>. See also :retab and ins-expandtab.
NOTE: This option is reset when 'compatible' is set.
Use :set shiftwidth=4
(or :set shiftwidth=8
) to control how many spaces are added per indent.
'shiftwidth' 'sw' number (default 8)
local to buffer
Number of spaces to use for each step of (auto)indent. Used for
'cindent', >>, <<, etc.
Other settings of interest are softtabstop
, tabstop
and autoindent
.