In the following example:
- Why in the first line, a
\tis inserted but only 4-col blank is displayed? Shouldn't it be
- Why the two
<TAB>hits in the first line and fifth lines have different results? (one is
09and the other is
set noexpandtab set tabstop=8 set shiftwidth=4 set softtabstop=4
I created the following text by first inserting 8 empty lines and then typing at the beginning of each line, so that there is no
shiftwidth generated. (each 4-col blank below is inserted by hitting
1tab done 2tabs done 3tabs done 4tabs done 1tab 2tabs 3tabs 4tabs
Then I did
:%!xxd, this is what I got (with some trailing newlines):
0000000: 3174 6162 0964 6f6e 650a 3274 6162 7309 1tab.done.2tabs. 0000010: 2020 2020 646f 6e65 0a33 7461 6273 0909 done.3tabs.. 0000020: 646f 6e65 0a34 7461 6273 0909 2020 2020 done.4tabs.. 0000030: 646f 6e65 0a20 2020 2031 7461 620a 0932 done. 1tab..2 0000040: 7461 6273 0a09 2020 2020 3374 6162 730a tabs.. 3tabs. 0000050: 0909 3474 6162 730a 0a0a 0a0a 0a0a 0a0a ..4tabs.........
There are some pretty good answers here but I still don't understand what is going on in this particular case.
(PS: this thread was posted here but no comprehensive solution is found so I'm reposting it now.)
The link from @EvergreenTree below is very helpful and almost solved my problem, however it seems not to answer my second question.
Solution (adapted from Christ's answer below)
tabstop=8does not necessarily mean each
\tis displayed as 8 columns, instead it means each
\tis displayed as ALIGNED to 8 columns.
<TAB>hit (in contrast to
tabstopabove) is displayed as aligned to 4 columns.
<TAB>hit may generate
\t, spaces, or a mixture of them, depending on the current position of cursor. More precisely, it will advance to next position aligned with
softtabstop. If this position is not aligned with
tabstop, spaces will be inserted. If it is,
\twill be inserted and redundant former spaces will be removed if needed. (see the video provided by @EvergreenTree below for an example of removing previously existed spaces).