This is the seventh day of my participation in the August More text Challenge. For details, see: August More Text Challenge
0. References
- Tabs and Spaces
1. Configuration items of the Tab key and space bar
Vim provides four fine-grained configuration items for Spaces:
tabstop
: Specify atab
The width of a character, abbreviated asts
.expandtab
: Activating this item will allow Spaces insteadtab
Character required to disable the itemnoexpandtab
.softtabstop
: Specifies how many Spaces to use insteadtab
Character, abbreviated tosts
.shiftwidth
: Specifies the number of Spaces inserted or deleted by the indent command in normal mode. Abbreviated assw
.
2. Example demonstration
The default Settings
ts=8 sts=0 sw=8 noexpandtab
Vim
The default setting in is a TAB character\t
To represent thetab
Key, do not replace with Spaces- Inserting a backspace key in mode removes tabs
- The width of the TAB character is
8
列 - Use in normal mode
<
or>
When you adjust indentation, you delete and add tabs
ts=8 sts=0 sw=8 expandtab
- The difference from the default setting is that it is enabled
expandtab
options Vim
Will use8
One space instead of a TAB- The backspace key in insert mode removes only one space at a time
- Use in normal mode
<
or>
When adjusting indent, reduce or add at once8
A blank space
ts=8 sts=8 sw=8 expandtab
softtabstop
Set to8
In insert mode, the backspace key can be deleted once8
A blank space- The indentation in normal mode is the same as before, because there are no modifications
shiftwidth
options - In general,
softtabstop
Need to beshiftwidth
Equal, as used in insert modetab
And the backspace key behaves the same as when used in normal mode<
和>
Adjust the indent behavior to be consistent.
ts=8 sts=4 sw=4 expandtab
- Activate the
expandtab
Option, all inserted tabs are replaced with Spaces. - Insert mode, because
softtabstop
Settings, usetab
And the backspace key4
A blank space. - The same is true for indentation in normal mode
4
A space. This is made up ofshiftwidth
A decision. - But if there are existing
\t
TAB, which will occupy8
A column width.
ts=8 sts=4 sw=4 noexpandtab
- use
noexpandtab
Will not usetab
Key instead of space. softtabstop
Set to4
, it takes precedence overtabstop
. So in insert mode we typetab
, will first enter4
A space, only one more presstab
, the original input is deleted4
One space, one space8
Replace it with a TAB character of a column width.- In normal mode, because
shiftwidth
Set to4
, so the behavior when using the indent command is similar to that in insert mode.
ts=4 sts=4 sw=4 noexpandtab
- To reduce
tabstop
到4
, you can see a TAB occupied4
A column width. - Used in insert mode
tab
The TAB is operated on by the backspace key and the indent command in normal mode.
Also set ts = STS = sw
- If you don’t want Spaces and tabs mixed up, make sure
tabstop
Is equal to thesofttabstop
. - If you only want to use Spaces instead of tabs, then you need to
softtabstop
Is equal to theshiftwidth
. - So in general, it’s a good idea to set all three values at the same time and make them equal.
Completed in 2019.7.4