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 atabThe width of a character, abbreviated asts.
  • expandtab: Activating this item will allow Spaces insteadtabCharacter required to disable the itemnoexpandtab.
  • softtabstop: Specifies how many Spaces to use insteadtabCharacter, 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
  • VimThe default setting in is a TAB character\tTo represent thetabKey, do not replace with Spaces
  • Inserting a backspace key in mode removes tabs
  • The width of the TAB character is8
  • 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 enabledexpandtaboptions
  • VimWill use8One 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 once8A blank space

ts=8 sts=8 sw=8 expandtab

  • softtabstopSet to8In insert mode, the backspace key can be deleted once8A blank space
  • The indentation in normal mode is the same as before, because there are no modificationsshiftwidthoptions
  • In general,softtabstopNeed to beshiftwidthEqual, as used in insert modetabAnd 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 theexpandtabOption, all inserted tabs are replaced with Spaces.
  • Insert mode, becausesofttabstopSettings, usetabAnd the backspace key4A blank space.
  • The same is true for indentation in normal mode4A space. This is made up ofshiftwidthA decision.
  • But if there are existing\tTAB, which will occupy8A column width.

ts=8 sts=4 sw=4 noexpandtab

  • usenoexpandtabWill not usetabKey instead of space.
  • softtabstopSet to4, it takes precedence overtabstop. So in insert mode we typetab, will first enter4A space, only one more presstab, the original input is deleted4One space, one space8Replace it with a TAB character of a column width.
  • In normal mode, becauseshiftwidthSet to4, so the behavior when using the indent command is similar to that in insert mode.

ts=4 sts=4 sw=4 noexpandtab

  • To reducetabstop4, you can see a TAB occupied4A column width.
  • Used in insert modetabThe 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 suretabstopIs equal to thesofttabstop.
  • If you only want to use Spaces instead of tabs, then you need tosofttabstopIs 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