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
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|
|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>