vim的tab

There are four main ways to use tabs in Vim:
Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4(or 3 or whatever you prefer) and use 'noexpandtab'.  Then Vim will use a mix of tabs and spaces, but typing <Tab> and <BS> will behave like a tab appears every 4 (or 3) characters.
始终将tabstop设置为8,始终将softtabstop和shiftwidth设置为4(或3或你想设置的那个值),并设置noexpandtab。这样的话Vim将混合使用tab和space,但是输入tab和空格将会表现得像每4个(或3个)字符一个tab
Set 'tabstop' and 'shiftwidth' to whatever you prefer and use 'expandtab'. This way you will always insert spaces. The formatting will never be messed up when 'tabstop' is changed.
未完
Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a modeline to set these values when editing the file again. Only works when using Vim to edit the file.
未完
Always set 'tabstop' and 'shiftwidth' to the same value, and 'noexpandtab'. This should then work (for initial indents only) for any tabstop setting that people use. It might be nice to have tabs after the first non-blank inserted as spaces if you do this though. Otherwise aligned comments will be wrong when 'tabstop' is changed.
未完

假设有以下设置,看看expandtab和noexpandtab的区别
set tabstop=8
set softtabstop=4
set shiftwidth=4
set expandtab

如果设置expandtab,硬翻译就是“打碎的tab”,这样的话,按一下tab就等于打上4个空格,整篇文档没有tab的,只有空格
如果设置noexpandtab,就会适时的将空格和tab的混合体,合并成一个tab(只要字符长度达到tabstop的值8的长度)
比如:在一个空白行前,第一次按tab时,会打上4个空格,第2次继续按tab时会再打上4个空格,之后noexpandtab自动起作用了,它会把8个空格变成一个tab,当然显示出来的样子还是8个字符宽,所以会察觉不到,但底层已经把8个空格变成1个tab了,可以通过(:set list)查看,也可以通过文件大小查看


你可能感兴趣的:(vim的tab)