VIM: Set the Width of a Single TAB to 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.

Steps

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

Additional

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.

Rick Donato

Want to become a UNIX expert?

Here is our hand-picked selection of the best courses you can find online:
UNIX Administration Fundamentals
Vim Masterclass
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial