O'Reilly logo

Mastering Vim by Ruslan Osipov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting variables

You've already discovered some basics of Vimscript syntax. To set internal Vim options, you use the set keyword:

set background=dark

To assign a value to a non-internal variable, use the let keyword:

let animal_name = 'Miss Cattington'

Vimscript doesn't have explicit booleans, so 1 is treated as true and 0 as false:

let is_cat = 1

Since we're assigning variables, let's talk about scopes. Vim handles variable and function scopes with prefixes, like so:

let g:animal_name = 'Miss Cattington'let w:is_cat=1

Each letter has a unique meaning, in particular the following:

  • g: global scope (default if scope is not specified)
  • v: global defined by Vim
  • l: local scope (default within a function if scope is not specified)
  • b: current ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required