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:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard

Radxa ROCK 5C (Lite) SBC with Rockchip RK3588 / RK3582 SoC

Leave a Reply

Your email address will not be published. Required fields are marked *

Khadas VIM4 SBC
Khadas VIM4 SBC