How To Force vim to Convert Tabs to Spaces

To create indents with 4 space characters which are entered by pressing the TAB key:
1 |
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab |
To make the above settings permanent add to your ~/.vimrc
file.
For more details on any of these see :help ‘optionname’ in vim (e.g. :help ‘tabstop’)
tabstop
The width of a hard tabstop measured in “spaces” — effectively the (maximum) width of an actual tab character.
shiftwidth
The size of an “indent”. It’s also measured in spaces, so if your code base indents with tab characters then you want shiftwidth to equal the number of tab characters times tabstop. This is also used by things like the =, > and < commands.
softtabstop
Setting this to a non-zero value other than tabstop will make the tab key (in insert mode) insert a combination of spaces (and possibly tabs) to simulate tab stops at this width.
expandtab
Enabling this will make the tab key (in insert mode) insert spaces instead of tab characters. This also affects the behavior of the retab command.
smarttab
Enabling this will make the tab key (in insert mode) insert spaces or tabs to go to the next indent of the next tabstop when the cursor is at the beginning of a line (i.e. the only preceding characters are whitespace).
Leave Your Comment
All fields marked with "*" are required.