使用expandtab后将tabstop从4更改为2(手动操作最少)

Jay*_*esh 3 vim tabs tabstop

有一段时间我在源文件中使用了tabstop = 4.现在我写了很多有深度缩进的javascript,一个4的tabstop似乎很浪费,所以我想把它转换为2.问题是我也使用"set expandtab".所以仅设置tabstop = 2,将无济于事.

关于如何将我的所有文件快速转换为tabstop 2的任何建议?

我目前相关的.vimrc设置是

set tabstop=4
set shiftwidth=4
set expandtab
Run Code Online (Sandbox Code Playgroud)

Alo*_*hal 11

你可以做

" 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!
Run Code Online (Sandbox Code Playgroud)

在vim窗口中,它将根据您的喜好重新收藏.您可以创建映射以使其更容易,或记录宏.可能有另一种方式,但上述方法应该有效.("是评论)


Mer*_*ham 6

您可以更改设置,选择全部,然后=按键以缩进它:

ggVG=
Run Code Online (Sandbox Code Playgroud)

我还建议使用ftplugin指定每种文件类型的设置.