In Vim, you can make tabs act as 4 spaces by setting a few options.
Inside Vim, run:
:set tabstop=4
:set shiftwidth=4
:set expandtabtabstop=4→ a tab character is shown as 4 spaces wideshiftwidth=4→ indentation commands use 4 spacesexpandtab→ pressingTabinserts spaces instead of a tab character
Add this to your ~/.vimrc (create it if it doesn’t exist):
set tabstop=4
set shiftwidth=4
set expandtabIf you want to quickly switch between tabs vs. spaces in Vim:
-
To turn spaces back into actual tabs:
:set noexpandtab
-
To convert existing tabs to spaces in the file:
:retab