The setting that controls whether <Tab>
and autoindent insert tabs or spaces is
" spaces
set expandtabs
" tabs
set noexpandtabs
This works in conjunction with tabstop
, softtabstop
and shiftwidth
settings (you most likely want to keep these equal):
set tabstop=4 softtabstop=4 shiftwidth=4
You can also abbreviate all of these:
set et ts=4 sts=4 sw=4
Once your options are set, you can convert the current file's unwanted tabs to spaces (or unwanted spaces to tabs, if noexpandtabs
) by issuing the :retab
command.
Using a modeline in each file (:help modeline
) or a project editorconfig with the editorconfig editor plugin are advisable to avoid this situation in the future when sharing code with individuals with unknown editor defaults.