Change tabstop from 4 to 2 after using expandtab (with minimal manual effort)

For some time, I used tabstop = 4 in my source files. Now when I write a lot of javascript with deep recesses, the tabstop of 4 seems wasteful, so I want to convert it to 2. The problem is that I also use "set expandtab". So just setting tabstop = 2 will not help.

Any suggestions on how to quickly convert all my files to tabstop 2?

My current relevant .vimrc options

set tabstop=4
set shiftwidth=4
set expandtab
+3
source share
2 answers

You can do

" convert spaces to tabs first
set noexpandtab
set tabstop=4
set shiftwidth=4
retab!
" now you have tabs instead of spaces, so insert spaces according to
" your new preference
set tabstop=2
set shiftwidth=2
set expandtab
retab!

vim, retab . , , . , , . (" - )

+10

, =, :

ggVG=

ftplugin .

+5

Source: https://habr.com/ru/post/1760458/


All Articles