VIM - How do I make the width of a single TAB only 4 spaces wide ?

In this extremely short article we will provide you with the steps required to make the width of a single TAB only 4 spaces wide.
This especially useful when using Visual Mode within VIM , in that you can indent large portions of text.


Within your ~/.vimrc file add the following lines.

set shiftwidth=4   " change the number of space characters inserted for indentation
set expandtab      " insert spaces whenever a tab key is pressed
set softtabstop=4  " makes the spaces feel like real tabs


There are 2 other VIM commands that can be especially useful, when dealing with TAB's. They are:

:set list - shows unprintable characters.
:retab - converts all TABs to spaces.

Note : Both of the above commands are run directly within the VIM terminal.


About the Author


R Donato

Rick Donato is the Founder and Chief Editor of He currently works as an SDN/NFV Solutions Architect and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001