chapters/02.markdown @ 004078be4e90

Yeah let's face it, it's not short any more.
author Steve Losh <steve@stevelosh.com>
date Fri, 12 Oct 2012 19:05:27 -0400
parents 33e01424adaa
children 78f061a9fff8
Setting Options
===============

Vim has many options you can set to change how it behaves.

There are two main kinds of options: boolean options (either "on" or "off") and
options that take a value.

Run the following command:

    :::vim
    :set number

Line numbers should appear in Vim.  Now run this:

    :::vim
    :set nonumber

The line numbers should disappear.  `number` is a boolean option -- it can be
off or on.  You turn it "on" by running `:set number` and "off" with `:set
nonumber`.

Toggling Options
----------------

You can also "toggle" boolean options to set them to the *opposite* of whatever
they are now.  Run this:

    :::vim
    :set number!

The line numbers should reappear.  Now run it again:

    :::vim
    :set number!

They should disappear once more.  Adding a `!` (exclamation point or "bang") to
a boolean option toggles it.

Checking Options
----------------

You can ask Vim what an option is currently set to by using a `?`.  Run these
commands and watch what happens after each:

    :::vim
    :set number
    :set number?
    :set nonumber
    :set number?

Notice how the first `:set number?` command displayed `number` while the second
displayed `nonumber`.

Options with Values
-------------------

Some options take a value instead of just being off or on.  Run the following
commands and watch what happens after each:

    :::vim
    :set number
    :set numberwidth=10
    :set numberwidth=4
    :set numberwidth?

The `numberwidth` option changes how wide the column containing line numbers
will be.

Try checking what a few other common options are set to:

    :::vim
    :set wrap?
    :set shiftround?
    :set matchtime?

Setting Multiple Options at Once
--------------------------------

Finally, you can specify more than one option in the same `:set` command.  Try
running this:

    :::vim
    :set number numberwidth=6

Exercises
---------

Read `:help 'number'` (note the quotes).

Read `:help relativenumber`.

Read `:help numberwidth`.

Read `:help wrap`.

Read `:help shiftround`.

Read `:help matchtime`.

Add a few lines to your vimrc file to set these options however you like.