Vim Tips Wiki
Register
No edit summary
(Change <tt> to <code>, perhaps also minor tweak.)
Tag: rollback
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{review}}
 
{{Tip
 
 
|id=37
 
|id=37
  +
|previous=36
|title=The basic operation about vim-boolean optionals
 
  +
|next=38
|created=March 7, 2001 6:47
+
|created=2001
 
|complexity=basic
 
|complexity=basic
|author=slimzhao--AT--21cn.com
+
|author=slimzhao
|version=5.7
+
|version=6.0
 
|rating=9/6
 
|rating=9/6
  +
|category1=Getting started
|text=
 
  +
|category2=Options
 
}}
 
}}
  +
The options that configure Vim are of three types:
{| cellspacing="0" border="1"
 
  +
*boolean : on or off (example {{help|'autochdir'}})
| <code>:set number </code> || switch the number on
 
  +
*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.
  +
  +
{| class="wikitable"
 
| <code>:set number</code> || Turn line numbers on
 
|-
 
|-
| <code>:set nonumber</code> || switch it off
+
| <code>:set nonumber</code> || Turn line numbers off
 
|-
 
|-
| <code>:set invnumber</code> <br/> <code>:set number!</code> || switch it inverse against the current setting
+
| <code>:set invnumber</code><br/><code>:set number!</code> || Toggle line numbers
|-
+
|-
| <code>:set number&amp;</code> || get the default value vim assums
+
| <code>:set number&</code> || Set option to default value
|-
+
|-
| <code>:set number?</code> || get the current value
+
| <code>:set number?</code> || Show value of option
 
|}
 
|}
   
Replace number with any legal vim-boolean optionals, they all works well.
+
Replace <code>number</code> with any boolean option.
  +
  +
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:
For vim-non-boolean optionals
 
  +
<pre>
:set optional&amp;
 
  +
nnoremap <F12> :set number!<CR>
also works properly.
 
  +
</pre>
   
  +
==References==
  +
*{{help|set-option}}
   
== Comments ==
+
==Comments==
<!-- parsed by vimtips.py in 1.105040 seconds-->
 
[[Category:Options]]
 

Revision as of 05:09, 13 July 2012

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

References

Comments