Vim Tips Wiki

Managing set options

Redirected from VimTip37

1,623pages on
this wiki
Add New Page
Add New Page Talk0
Tip 37 Printable Monobook Previous Next

created 2001 · complexity basic · author slimzhao · version 6.0

The options that configure Vim are of three types:

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 optionsEdit

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 optionEdit

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"
    set mouse=a
    echo "Mouse usage enabled"

It's easier to toggle a boolean option, for example:

nnoremap <F12> :set number!<CR>



  • Vim settings editing app for Mac - a GUI tool to edit "set" options.
  • Also see the :options command for a similar built-in editable list of current option values.

Also on Fandom

Random Wiki