Content Entry

VIM: Converting tabs to spaces

Published: 2007-11-14 Categories: GNU/Linux Tags: Linux vi vim

created: February 24, 2001 18:02
complexity: basic
author: Yegappan
as of Vim: 5.7

To insert space characters whenever the tab key is pressed, set the
'expandtab' option:

set expandtab

With this option set, if you want to enter a real tab character use
Ctrl-V key sequence.

To control the number of space characters that will be inserted when
the tab key is pressed, set the 'tabstop' option. For example, to
insert 4 spaces for a tab, use:

set tabstop=4

After the 'expandtab' option is set, all the new tab characters entered
will be changed to spaces. This will not affect the existing tab
characters. To change all the existing tab characters to match the
current tab settings, use


To change the number of space characters inserted for indentation, use
the 'shiftwidth' option:

set shiftwidth=4

For example, to get the following coding style,
- No tabs in the source file
- All tab characters are 4 space characters

use the following set of options:

set tabstop=4
set shiftwidth=4
set expandtab

Add the above settings to your .vimrc file.

To get more help on these options, use
:help tabstop
:help shiftwidth
:help expandtab

comments loading