Replacing tabs by spaces in vi

In order to have code formatting consistency, we may choose to use only tabs or only spaces in the source code.

We chose to only use spaces since that makes sure the code will be properly formatted in any text editor.

In order to create 4 spaces while pressing tabs in vi, edit your vi settings:

vi ~/.vimrc

and add the 3 lines below to your config file

set tabstop=4
set shiftwidth=4
set expandtab

The next time you’ll use vi, pressing the tabulation key will create 4 spaces.

However, in some cases, e.g. Makefile, you may still need to use real tabs. Just press Ctrl+V then tab to create a real tab.

Share this:

Support CNX Software! Donate via cryptocurrencies or become a Patron on Patreon

ROCK Pi 4C Plus

PCBWay custom PCB service
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
0 Comments
Weller PCB manufacturer