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 app
若是設置expandtab,硬翻譯就是「打碎的tab」,這樣的話,按一下tab就等於打上4個空格,整篇文檔沒有tab的,只有空格
若是設置noexpandtab,就會適時的將空格和tab的混合體,合併成一個tab(只要字符長度達到tabstop的值8的長度)
好比:在一個空白行前,第一次按tab時,會打上4個空格,第2次繼續按tab時會再打上4個空格,以後noexpandtab自動起做用了,它會把8個空格變成一個tab,固然顯示出來的樣子仍是8個字符寬,因此會察覺不到,但底層已經把8個空格變成1個tab了,能夠經過(:set list)查看,也能夠經過文件大小查看 this