René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback

Variables in vim

... yet to be finished ...


function! ArrayTest()

  let i_{1} = "one"
  let i_{2} = "two"
  let i_{3} = "three"

  let j = 1
  while j<=3 
    echo "i_{".j."} = " i_{j}
    let j=j+1

See also vim's help (:help curly-braces-names) for more details.

Interpolated variables

let a='foo'
let b='bar'

let cfoo='hello'
let cbar='bye'

echo c{a}
echo c{b}
This prints hello followed by bye.


Variables can be prefixed with a letter and a colon. Vim doco calls these name spaces for variables
b: Buffer
w: Window
g: Global
l: Function
s: Script variable (or Sourced script?)
a: Arguments to Function
v: Global, predefined
@ registers
&XYZ The value of an option (for example ic)
If a function is declared with range, the the special variables a:firstline and a:lastline give the numbers where the selection starts and ends.
Additionally, the value of an option can be set/gotten by preceding the option name with a & (For example &shell or &term).
The value of environment variables can be gotten by preceding the variable's name with a $ (For example $VIM).
@/ is the value of the last search pattern. This value can be assigned to.

Variables with a meaning to vim

Environment variables

  • $HOME
  • $VIM
  • ....

global variables

  • did_load_filetypes
  • ft_ignore_pat
  • syntax_cmd
  • ...

Saving variables accross sessions

If the viminfo option has the !, the global variables with upper case letters will be stored in the viminfo file.
If the sessionoptions option has the global flag, then global variables starting with an upper case letter will be stored in the sessionfile.