💾 Archived View for gmi.noulin.net › vim › options.gmi captured on 2024-08-25 at 05:03:41. Gemini links have been rewritten to link to archived content
View Raw
More Information
⬅️ Previous capture (2024-08-19)
🚧 View Differences
-=-=-=-=-=-=-
- options.txt* For Vim version 9.1. Last change: 2024 Aug 12
VIM REFERENCE MANUAL by Bram Moolenaar
Options *options*
1. Setting options |set-option|
2. Automatically setting options |auto-setting|
3. Options summary |option-summary|
For an overview of options see quickref.txt |option-list|.
Vim has a number of internal variables and switches which can be set to
achieve special effects. These options come in three forms:
boolean can only be on or off *boolean* *toggle*
number has a numeric value
string has a string value
==============================================================================
1. Setting options *set-option* *E764*
*:se* *:set*
:se[t][!] Show all options that differ from their default value.
When [!] is present every option is on a separate
line.
:se[t][!] all Show all but terminal options.
When [!] is present every option is on a separate
line.
:se[t] termcap Show all terminal options. Note that in the GUI the
key codes are not shown, because they are generated
internally and can't be changed. Changing the terminal
codes in the GUI is not useful either...
The options have the form t_AB, see
|terminal-options|.
:se[t]! termcap Idem, but don't use multiple columns.
*E518* *E519*
:se[t] {option}? Show value of {option}.
:se[t] {option} Toggle option: set, switch it on.
Number option: show value.
String option: show value.
:se[t] no{option} Toggle option: Reset, switch it off.
*:set-!* *:set-inv*
:se[t] {option}! or
:se[t] inv{option} Toggle option: Invert value.
*:set-default* *:set-&* *:set-&vi* *:set-&vim*
:se[t] {option}& Reset option to its default value. May depend on the
current value of 'compatible'.
:se[t] {option}&vi Reset option to its Vi default value.
:se[t] {option}&vim Reset option to its Vim default value.
:se[t] all& Set all options to their default value. The values of
these options are not changed:
all terminal options, starting with t_
'columns'
'cryptmethod'
'encoding'
'key'
'lines'
'term'
'ttymouse'
'ttytype'
Warning: This may have a lot of side effects.
*:set-args* *:set=* *E487* *E521*
:se[t] {option}={value} or
:se[t] {option}:{value}
Set string or number option to {value}.
For numeric options the value can be given in decimal,
hex (preceded with 0x) or octal (preceded with '0' or
'0o').
The old value can be inserted by typing 'wildchar' (by
default this is a <Tab> or CTRL-E if 'compatible' is
set). Many string options with fixed syntax and names
also support completing known values. See
|cmdline-completion| and |complete-set-option|.
White space between {option} and '=' is allowed and
will be ignored. White space between '=' and {value}
is not allowed.
See |option-backslash| for using white space and
backslashes in {value}.
:se[t] {option}+={value} *:set+=*
Add the {value} to a number option, or append the
{value} to a string option. When the option is a
comma-separated list, a comma is added, unless the
value was empty.
If the option is a list of flags, superfluous flags
are removed. When adding a flag that was already
present the option value doesn't change.
Also see |:set-args| above.
:se[t] {option}^={value} *:set^=*
Multiply the {value} to a number option, or prepend
the {value} to a string option. When the option is a
comma-separated list, a comma is added, unless the
value was empty.
Also see |:set-args| above.
:se[t] {option}-={value} *:set-=*
Subtract the {value} from a number option, or remove
the {value} from a string option, if it is there.
If the {value} is not found in a string option, there
is no error or warning. When the option is a comma
separated list, a comma is deleted, unless the option
becomes empty.
When the option is a list of flags, {value} must be
exactly as they appear in the option. Remove flags
one by one to avoid problems.
The individual values from a comma separated list or
list of flags can be inserted by typing 'wildchar'.
See |complete-set-option|.
Also see |:set-args| above.
The {option} arguments to ":set" may be repeated. For example: >
:set ai nosi sw=3 ts=3
If you make an error in one of the arguments, an error message will be given
and the following arguments will be ignored.
*:set-verbose*
When 'verbose' is non-zero, displaying an option value will also tell where it
was last set. Example: >
:verbose set shiftwidth cindent?
< shiftwidth=4 ~
Last set from modeline line 1 ~
cindent ~
Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~
This is only done when specific option values are requested, not for ":verbose
set all" or ":verbose set" without an argument.
When the option was set by hand there is no "Last set" message.
When the option was set while executing a function, user command or
autocommand, the script in which it was defined is reported.
Note that an option may also have been set as a side effect of setting
'compatible'.
A few special texts:
Last set from modeline line 1 ~
Option was set in a |modeline|.
Last set from --cmd argument ~
Option was set with command line argument |--cmd| or +.
Last set from -c argument ~
Option was set with command line argument |-c|, +, |-S| or
|-q|.
Last set from environment variable ~
Option was set from an environment variable, $VIMINIT,
$GVIMINIT or $EXINIT.
Last set from error handler ~
Option was cleared when evaluating it resulted in an error.
{not available when compiled without the |+eval| feature}
*:set-termcap* *E522*
For {option} the form "t_xx" may be used to set a terminal option. This will
override the value from the termcap. You can then use it in a mapping. If
the "xx" part contains special characters, use the <t_xx> form: >
:set <t_#4>=^[Ot
This can also be used to translate a special code for a normal key. For
example, if Alt-b produces <Esc>b, use this: >
:set <M-b>=^[b
(the ^[ is a real <Esc> here, use CTRL-V <Esc> to enter it)
The advantage over a mapping is that it works in all situations.
You can define any key codes, e.g.: >
:set t_xy=^[foo;
There is no warning for using a name that isn't recognized. You can map these
codes as you like: >
:map <t_xy> something
< *E846*
When a key code is not set, it's like it does not exist. Trying to get its
value will result in an error: >
:set t_kb=
:set t_kb
< E846: Key code not set: t_kb ~
The t_xx options cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
The listing from ":set" looks different from Vi. Long string options are put
at the end of the list. The number of options is quite large. The output of
"set all" probably does not fit on the screen, causing Vim to give the
|more-prompt|.
*option-backslash*
To include white space in a string option value it has to be preceded with a
backslash. To include a backslash you have to use two. Effectively this
means that the number of backslashes in an option value is halved (rounded
down).
In options 'path', 'cdpath', and 'tags', spaces have to be preceded with three
backslashes instead for compatibility with version 3.0 where the options can
be separated by either commas or spaces.
Comma-separated options like 'backupdir' and 'tags' will also require commas
to be escaped with two backslashes, whereas this is not needed for
non-comma-separated ones like 'makeprg'.
When setting options using |:let| and |literal-string|, you need to use one
fewer layer of backslash.
A few examples: >
:set makeprg=make\ file results in "make file"
:let &makeprg='make file' (same as above)
:set makeprg=make\\\ file results in "make\ file"
:set tags=tags\ /usr/tags results in "tags" and "/usr/tags"
:set tags=tags\\\ file results in "tags file"
:let &tags='tags\ file' (same as above)
:set makeprg=make,file results in "make,file"
:set makeprg=make\\,file results in "make\,file"
:set tags=tags,file results in "tags" and "file"
:set tags=tags\\,file results in "tags,file"
:let &tags='tags\,file' (same as above)
The "|" character separates a ":set" command from a following command. To
include the "|" in the option value, use "\|" instead. This example sets the
'titlestring' option to "hi|there": >
:set titlestring=hi\|there
This sets the 'titlestring' option to "hi" and 'iconstring' to "there": >
:set titlestring=hi|set iconstring=there
Similarly, in legacy script the double quote character starts a comment. To
include the '"' in the option value, use '\"' instead. This example sets the
'titlestring' option to 'hi "there"': >
:set titlestring=hi\ \"there\"
In |Vim9| script it's simpler, comments start with a '#' character, and only
when preceded by white space. A backslash is needed less often: >
vim9script
set titlestring=hi\ "there"
set titlestring=hi#there#
set titlestring=hi\ \#there#
For Win32 backslashes in file names are mostly not removed. More precise: For
options that expect a file name (those where environment variables are
expanded) a backslash before a normal file name character is not removed. But
a backslash before a special character (space, backslash, comma, etc.) is used
like explained above.
There is one special situation, when the value starts with "\\": >
:set dir=\\machine\path results in "\\machine\path"
:set dir=\\\\machine\\path results in "\\machine\path"
:set dir=\\path\\file results in "\\path\file" (wrong!)
For the first one the start is kept, but for the second one the backslashes
are halved. This makes sure it works both when you expect backslashes to be
halved and when you expect the backslashes to be kept. The third gives a
result which is probably not what you want. Avoid it.
*add-option-flags* *remove-option-flags*
*E539* *E550* *E551* *E552*
Some options are a list of flags. When you want to add a flag to such an
option, without changing the existing ones, you can do it like this: >
:set guioptions+=a
Remove a flag from an option like this: >
:set guioptions-=a
This removes the 'a' flag from 'guioptions'.
Note that you should add or remove one flag at a time. If 'guioptions' has
the value "ab", using "set guioptions-=ba" won't work, because the string "ba"
doesn't appear.
*:set_env* *expand-env* *expand-environment-var*
Environment variables in specific string options will be expanded. If the
environment variable exists the '