paperlined.org
apps > vim > vim_script
document updated 13 years ago, on Sep 8, 2011
documentation

Very gentle introduction to basic syntax

:echo 'foo bar'
Displays that string.
:echo 'foo' | echo 'bar'
The bar allows two commands to be run on the same cmdline. (NOTE some real exceptions, however)
:let somevar = 5 | echo 'the value of "somevar" is' somevar
Example of creating a variable, and doing variable expansion. The right side of 'let' can be any expression.

There are several types of variables, and different types of explicitely-declared scopes.

:echo &modeline
This is how to display a built-in setting's value.
:echo tolower("FOOBAR") | echo "The ASCII value of 'o' is " char2nr("o")
There are many functions available.
:let cmd = 'echo' | execute cmd 'tolower("FOOBAR")'
:execute can make variable-interpolation work, akin to eval().
:debug let cmd = 'echo' | execute cmd 'tolower("FOOBAR")'
Prepending 'debug' and then typing 'step' repeatedly can be illuminating.
:let varA = "foo" | let varB = "bar"
:execute 'echo "' varA varB '"' |" displays " foo bar"
:execute 'echo "' . varA . varB . '"' |" displays "foobar"
Both 'execute' and 'echo' always add a space between their arguments. However, you can use the string-concatenation operator ('.') to avoid this space-adding behavior.

More complicated syntax