fir3net
PPS-Firenetbanner-780.5x190-30-03-17

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.

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.

Tags: VIM, UNIX

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001