JohnBeckett (talk | contribs) m (Managing boolean options moved to Managing set options: per 200808) |
JohnBeckett (talk | contribs) m (Reverted edits by 114.79.28.61 (talk | block) to last version by JohnBot) |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 3: | Line 3: | ||
|previous=36 |
|previous=36 |
||
|next=38 |
|next=38 |
||
− | |created= |
+ | |created=2001 |
|complexity=basic |
|complexity=basic |
||
|author=slimzhao |
|author=slimzhao |
||
− | |version= |
+ | |version=6.0 |
|rating=9/6 |
|rating=9/6 |
||
− | |category1= |
+ | |category1=Getting started |
− | |category2= |
+ | |category2=Options |
}} |
}} |
||
+ | The options that configure Vim are of three types: |
||
⚫ | |||
+ | *boolean : on or off (example {{help|'autochdir'}}) |
||
+ | *number : an integer value (example {{help|'textwidth'}}) |
||
+ | *string : a string value (example {{help|'backspace'}}) |
||
+ | Options can be global, or may apply only to a particular buffer or window. {{help|:setlocal}} |
||
− | {| cellspacing="0" border="1" |
||
+ | |||
⚫ | |||
+ | A quick list of options is at {{help|option-list}}, and all the details are at {{help|options}}. |
||
+ | |||
+ | ==Boolean options== |
||
⚫ | |||
+ | |||
+ | {| class="wikitable" |
||
⚫ | |||
|- |
|- |
||
| <code>:set nonumber</code> || Turn line numbers off |
| <code>:set nonumber</code> || Turn line numbers off |
||
|- |
|- |
||
− | | <code>:set invnumber</code> |
+ | | <code>:set invnumber</code><br/><code>:set number!</code> || Toggle line numbers |
|- |
|- |
||
− | | <code>:set number&</code> || Set |
+ | | <code>:set number&</code> || Set option to default value |
|- |
|- |
||
− | | <code>:set number?</code> || Show value of |
+ | | <code>:set number?</code> || Show value of option |
|} |
|} |
||
Replace <code>number</code> with any boolean option. |
Replace <code>number</code> with any boolean option. |
||
− | For nonboolean options, <code>:set option&</code> also sets the option to its default value |
+ | For nonboolean options, <code>:set option&</code> also sets the option to its default value, and <code>:set option?</code> will display the current value. |
+ | |||
+ | ==Toggling an option== |
||
+ | If you often need to change an option, you could use a mapping and script as in the following example (which could be placed in your [[vimrc]]). In this example, the F12 key is mapped to either enable or disable the mouse. |
||
+ | <pre> |
||
+ | nnoremap <F12> :call ToggleMouse()<CR> |
||
+ | function! ToggleMouse() |
||
+ | if &mouse == 'a' |
||
+ | set mouse= |
||
+ | echo "Mouse usage disabled" |
||
+ | else |
||
+ | set mouse=a |
||
+ | echo "Mouse usage enabled" |
||
+ | endif |
||
+ | endfunction |
||
+ | </pre> |
||
+ | |||
+ | It's easier to toggle a boolean option, for example: |
||
+ | <pre> |
||
+ | nnoremap <F12> :set number!<CR> |
||
+ | </pre> |
||
==References== |
==References== |
Revision as of 22:19, 2 April 2016
created 2001 · complexity basic · author slimzhao · version 6.0
The options that configure Vim are of three types:
- boolean : on or off (example :help 'autochdir')
- number : an integer value (example :help 'textwidth')
- string : a string value (example :help 'backspace')
Options can be global, or may apply only to a particular buffer or window. :help :setlocal
A quick list of options is at :help option-list, and all the details are at :help options.
Boolean options
The many ways to set a boolean option are best illustrated by a simple example. In the following, the 'number' option is used. Any boolean option, such as wrap, linebreak, diff, etc can be set in these ways.
:set number |
Turn line numbers on |
:set nonumber |
Turn line numbers off |
:set invnumber :set number! |
Toggle line numbers |
:set number& |
Set option to default value |
:set number? |
Show value of option |
Replace number
with any boolean option.
For nonboolean options, :set option&
also sets the option to its default value, and :set option?
will display the current value.
Toggling an option
If you often need to change an option, you could use a mapping and script as in the following example (which could be placed in your vimrc). In this example, the F12 key is mapped to either enable or disable the mouse.
nnoremap <F12> :call ToggleMouse()<CR> function! ToggleMouse() if &mouse == 'a' set mouse= echo "Mouse usage disabled" else set mouse=a echo "Mouse usage enabled" endif endfunction
It's easier to toggle a boolean option, for example:
nnoremap <F12> :set number!<CR>