mirror of
https://github.com/vim/vim
synced 2025-07-15 16:51:57 +00:00
runtime(doc): update documentation on tabstop settings
Unify the treatment of tabstop, correct errors and deprecate smarttab usage. closes: #17444 Signed-off-by: Damien Lejay <damien@lejay.be> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
274efcc7e6
commit
bfa16364f1
@ -1,4 +1,4 @@
|
|||||||
*options.txt* For Vim version 9.1. Last change: 2025 Jun 07
|
*options.txt* For Vim version 9.1. Last change: 2025 Jun 10
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -7803,11 +7803,13 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
global
|
global
|
||||||
When enabled, the <Tab> key will indent by 'shiftwidth' if the cursor
|
When enabled, the <Tab> key will indent by 'shiftwidth' if the cursor
|
||||||
is in leading whitespace. The <BS> key has the opposite effect.
|
is in leading whitespace. The <BS> key has the opposite effect.
|
||||||
This behaves as if 'softtabstop' is set to the value of 'shiftwidth'.
|
In leading whitespace, this has the same effect as setting
|
||||||
|
'softtabstop' to the value of 'shiftwidth'.
|
||||||
This option is reset when 'compatible' is set; it is temporarily
|
This option is reset when 'compatible' is set; it is temporarily
|
||||||
disabled when 'paste' is enabled, and restored when 'paste' is turned
|
disabled when 'paste' is enabled, and restored when 'paste' is turned
|
||||||
off.
|
off.
|
||||||
Have a look at section |30.5| of the user guide for detailed
|
NOTE: in most cases, using 'softtabstop' is a better option. Have a
|
||||||
|
look at section |30.5| of the user guide for detailed
|
||||||
explanations on how Vim works with tabs and spaces.
|
explanations on how Vim works with tabs and spaces.
|
||||||
|
|
||||||
*'smoothscroll'* *'sms'* *'nosmoothscroll'* *'nosms'*
|
*'smoothscroll'* *'sms'* *'nosmoothscroll'* *'nosms'*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*quickref.txt* For Vim version 9.1. Last change: 2025 Jun 04
|
*quickref.txt* For Vim version 9.1. Last change: 2025 Jun 10
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -942,7 +942,7 @@ Short explanation of each option: *option-list*
|
|||||||
'tabclose' 'tcl' which tab page to focus when closing a tab
|
'tabclose' 'tcl' which tab page to focus when closing a tab
|
||||||
'tabline' 'tal' custom format for the console tab pages line
|
'tabline' 'tal' custom format for the console tab pages line
|
||||||
'tabpagemax' 'tpm' maximum number of tab pages for |-p| and "tab all"
|
'tabpagemax' 'tpm' maximum number of tab pages for |-p| and "tab all"
|
||||||
'tabstop' 'ts' number of spaces that <Tab> in file uses
|
'tabstop' 'ts' number of columns between two tab stops
|
||||||
'tagbsearch' 'tbs' use binary searching in tags files
|
'tagbsearch' 'tbs' use binary searching in tags files
|
||||||
'tagcase' 'tc' how to handle case when searching in tags files
|
'tagcase' 'tc' how to handle case when searching in tags files
|
||||||
'tagfunc' 'tfu' function to get list of tag matches
|
'tagfunc' 'tfu' function to get list of tag matches
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*usr_25.txt* For Vim version 9.1. Last change: 2025 Feb 01
|
*usr_25.txt* For Vim version 9.1. Last change: 2025 Jun 10
|
||||||
|
|
||||||
VIM USER MANUAL - by Bram Moolenaar
|
VIM USER MANUAL - by Bram Moolenaar
|
||||||
|
|
||||||
@ -215,27 +215,28 @@ An alternative is to filter the text through an external program. Example: >
|
|||||||
*25.3* Indents and tabs
|
*25.3* Indents and tabs
|
||||||
|
|
||||||
Indents can be used to make text stand out from the rest. The example texts
|
Indents can be used to make text stand out from the rest. The example texts
|
||||||
in this manual, for example, are indented by eight spaces or a tab. You would
|
in this manual, for example, are indented by eight columns. You would
|
||||||
normally enter this by typing a tab at the start of each line. Take this
|
normally enter this by typing <Tab> at the start of each line. Take this
|
||||||
text:
|
text:
|
||||||
the first line ~
|
the first line ~
|
||||||
the second line ~
|
the second line ~
|
||||||
|
|
||||||
This is entered by typing a tab, some text, <Enter>, tab and more text.
|
This is entered by typing <Tab>, some text, <Enter>, <Tab> and more text.
|
||||||
The 'autoindent' option inserts indents automatically: >
|
The 'autoindent' option inserts indents automatically: >
|
||||||
|
|
||||||
:set autoindent
|
:set autoindent
|
||||||
|
|
||||||
When a new line is started it gets the same indent as the previous line. In
|
When a new line is started it gets the same indent as the previous line. In
|
||||||
the above example, the tab after the <Enter> is not needed anymore.
|
the above example, pressing the <Tab> key after <Enter> is not needed anymore.
|
||||||
|
|
||||||
|
|
||||||
INCREASING INDENT
|
INCREASING INDENT
|
||||||
|
|
||||||
To increase the amount of indent in a line, use the ">" operator. Often this
|
To increase the amount of indent in a line, use the ">" operator, in Normal
|
||||||
is used as ">>", which adds indent to the current line.
|
mode. Often this is used as ">>", which adds indent to the current line.
|
||||||
|
In Insert mode, use <C-t>.
|
||||||
The amount of indent added is specified with the 'shiftwidth' option. The
|
The amount of indent added is specified with the 'shiftwidth' option. The
|
||||||
default value is 8. To make ">>" insert four spaces worth of indent, for
|
default value is 8. To make ">>" insert four columns worth of indent, for
|
||||||
example, type this: >
|
example, type this: >
|
||||||
|
|
||||||
:set shiftwidth=4
|
:set shiftwidth=4
|
||||||
@ -248,46 +249,27 @@ When used on the second line of the example text, this is what you get:
|
|||||||
"4>>" will increase the indent of four lines.
|
"4>>" will increase the indent of four lines.
|
||||||
|
|
||||||
|
|
||||||
TABSTOP
|
SOFT TAB STOPS
|
||||||
|
|
||||||
If you want to make indents a multiple of 4, you set 'shiftwidth' to 4. But
|
If you want to make indents a multiple of 4, you set 'shiftwidth' to 4. But
|
||||||
when pressing a <Tab> you still get 8 spaces worth of indent. To change this,
|
when pressing a <Tab> you still get 8 columns worth of indent. To change
|
||||||
set the 'softtabstop' option: >
|
this, set the 'softtabstop' option: >
|
||||||
|
|
||||||
:set softtabstop=4
|
:set softtabstop=4
|
||||||
|
|
||||||
This will make the <Tab> key insert 4 spaces worth of indent. If there are
|
Vim now creates invisible tab stops for your cursor every 4 columns; hitting
|
||||||
already four spaces, a <Tab> character is used (saving seven characters in the
|
<Tab> jumps to the next stop and inserts the exact mix of spaces or tabs
|
||||||
file). (If you always want spaces and no tab characters, set the 'expandtab'
|
needed.
|
||||||
option.)
|
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
You could set the 'tabstop' option to 4. However, if you edit the
|
You could set the 'tabstop' option to 4. However, if you edit the
|
||||||
file another time, with 'tabstop' set to the default value of 8, it
|
file another time, with 'tabstop' set to the default value of 8, it
|
||||||
will look wrong. In other programs and when printing the indent will
|
will look wrong. In other programs and when printing the indent will
|
||||||
also be wrong. Therefore it is recommended to keep 'tabstop' at eight
|
also be wrong. Therefore it is recommended to keep 'tabstop' at eight
|
||||||
all the time. That's the standard value everywhere.
|
all the time. That's the standard value everywhere on UNIX-like
|
||||||
|
systems.
|
||||||
|
|
||||||
|
|
||||||
CHANGING TABS
|
|
||||||
|
|
||||||
You edit a file which was written with a tabstop of 3. In Vim it looks ugly,
|
|
||||||
because it uses the normal tabstop value of 8. You can fix this by setting
|
|
||||||
'tabstop' to 3. But you have to do this every time you edit this file.
|
|
||||||
Vim can change the use of tabstops in your file. First, set 'tabstop' to
|
|
||||||
make the indents look good, then use the ":retab" command: >
|
|
||||||
|
|
||||||
:set tabstop=3
|
|
||||||
:retab 8
|
|
||||||
|
|
||||||
The ":retab" command will change 'tabstop' to 8, while changing the text such
|
|
||||||
that it looks the same. It changes spans of white space into tabs and spaces
|
|
||||||
for this. You can now write the file. Next time you edit it the indents will
|
|
||||||
be right without setting an option.
|
|
||||||
Warning: When using ":retab" on a program, it may change white space inside
|
|
||||||
a string constant. Therefore it's a good habit to use "\t" instead of a
|
|
||||||
real tab.
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
*25.4* Dealing with long lines
|
*25.4* Dealing with long lines
|
||||||
|
|
||||||
@ -576,6 +558,32 @@ The "gR" command uses Virtual Replace mode. This preserves the layout:
|
|||||||
|
|
||||||
inp 0.786 0.534 0.693 ~
|
inp 0.786 0.534 0.693 ~
|
||||||
|
|
||||||
|
|
||||||
|
REFORMATTING TABS IN TABLES
|
||||||
|
|
||||||
|
You edit a file that contains tabular data and the original author of the file
|
||||||
|
decided to align the tabular data using tab characters (instead of spaces).
|
||||||
|
Alas, they were using tab stops separated by 4 columns and Vim's default
|
||||||
|
is 8 columns; the table looks wrong! What can be done?
|
||||||
|
To fix the appearance without modifying the file, adjust the setting
|
||||||
|
temporarily: >
|
||||||
|
|
||||||
|
:set tabstop=4
|
||||||
|
|
||||||
|
This updates the visual layout, but the file itself remains unchanged.
|
||||||
|
Another possibility is to permanently reformat the file. For this Vim
|
||||||
|
provides the |:retab| command. First, set 'tabstop' to match original layout
|
||||||
|
(as above), then run: >
|
||||||
|
|
||||||
|
:retab 8
|
||||||
|
|
||||||
|
The ":retab" command will change 'tabstop' to 8, while changing the text such
|
||||||
|
that it looks the same. It changes spans of white space into tabs and spaces
|
||||||
|
for this. You can now write the file.
|
||||||
|
Warning: When using ":retab" on a program, it may change white space inside
|
||||||
|
a string constant. Therefore it's a good habit to use "\t" instead of a
|
||||||
|
real tab.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
Next chapter: |usr_26.txt| Repeating
|
Next chapter: |usr_26.txt| Repeating
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*usr_30.txt* For Vim version 9.1. Last change: 2025 May 30
|
*usr_30.txt* For Vim version 9.1. Last change: 2025 Jun 10
|
||||||
|
|
||||||
VIM USER MANUAL - by Bram Moolenaar
|
VIM USER MANUAL - by Bram Moolenaar
|
||||||
|
|
||||||
@ -547,8 +547,8 @@ tab stops.
|
|||||||
|
|
||||||
If you prefer to have different values for 'shiftwidth' and 'softtabstop',
|
If you prefer to have different values for 'shiftwidth' and 'softtabstop',
|
||||||
you can still do so and use <C-t> to indent with 'shiftwidth'. Or you can
|
you can still do so and use <C-t> to indent with 'shiftwidth'. Or you can
|
||||||
use the 'smarttab' option introduced in Vim 5.6, allowing for a unified
|
use the 'smarttab' option, allowing for a unified <Tab> key that knows what to
|
||||||
<Tab> key that knows what to do in the different situations.
|
do in the different situations.
|
||||||
|
|
||||||
|
|
||||||
VARIABLE TAB STOPS
|
VARIABLE TAB STOPS
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*various.txt* For Vim version 9.1. Last change: 2025 Jun 07
|
*various.txt* For Vim version 9.1. Last change: 2025 Jun 10
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -514,7 +514,7 @@ T *+title* Setting the window 'title' and 'icon'; Always enabled
|
|||||||
N *+toolbar* |gui-toolbar|
|
N *+toolbar* |gui-toolbar|
|
||||||
T *+user_commands* User-defined commands. |user-commands|
|
T *+user_commands* User-defined commands. |user-commands|
|
||||||
Always enabled since 8.1.1210.
|
Always enabled since 8.1.1210.
|
||||||
H *+vartabs* Variable-width tabstops. |'vartabstop'|
|
H *+vartabs* Variable-width tab stops. |'vartabstop'|
|
||||||
T *+vertsplit* Vertically split windows |:vsplit|; Always enabled
|
T *+vertsplit* Vertically split windows |:vsplit|; Always enabled
|
||||||
since 8.0.1118.
|
since 8.0.1118.
|
||||||
T *+vim9script* |Vim9| script
|
T *+vim9script* |Vim9| script
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*vi_diff.txt* For Vim version 9.1. Last change: 2025 Jun 02
|
*vi_diff.txt* For Vim version 9.1. Last change: 2025 Jun 10
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -1102,7 +1102,7 @@ The following options are supported by Vi: ~
|
|||||||
'shiftwidth' 'sw' number of spaces to use for (auto)indent step
|
'shiftwidth' 'sw' number of spaces to use for (auto)indent step
|
||||||
'showmatch' 'sm' briefly jump to matching bracket if insert one
|
'showmatch' 'sm' briefly jump to matching bracket if insert one
|
||||||
'showmode' 'smd' message on status line to show current mode
|
'showmode' 'smd' message on status line to show current mode
|
||||||
'tabstop' 'ts' number of spaces that <Tab> in file uses
|
'tabstop' 'ts' number of columns between two tab stops
|
||||||
'taglength' 'tl' number of significant characters for a tag
|
'taglength' 'tl' number of significant characters for a tag
|
||||||
'tags' 'tag' list of file names used by the tag command
|
'tags' 'tag' list of file names used by the tag command
|
||||||
{Vi: default is "tags /usr/lib/tags"}
|
{Vi: default is "tags /usr/lib/tags"}
|
||||||
|
Reference in New Issue
Block a user