Download vim_doc.txt Page 1 *usr_toc.txt* For Vim version 6.3. Last change

Transcript
vim_doc.txt
Page 192
{statements}
:endif
This works just like using ":else" and then "if", but without the need for an
extra ":endif".
A useful example for your vimrc file is checking the 'term' option and
doing something depending upon its value:
:if &term == "xterm"
: " Do stuff for xterm
:elseif &term == "vt100"
: " Do stuff for a vt100 terminal
:else
: " Do something for other terminals
:endif
LOGIC OPERATIONS
We already used some of them in the examples.
ones:
a
a
a
a
a
a
==
!=
>
>=
<
<=
b
b
b
b
b
b
These are the most often used
equal to
not equal to
greater than
greater than or equal to
less than
less than or equal to
The result is one if the condition is met and zero otherwise.
An example:
:if v:version >= 600
: echo "congratulations"
:else
: echo "you are using an old version, upgrade!"
:endif
Here "v:version" is a variable defined by Vim, which has the value of the Vim
version. 600 is for version 6.0. Version 6.1 has the value 601. This is
very useful to write a script that works with multiple versions of Vim.
|v:version|
The logic operators work both for numbers and strings. When comparing two
strings, the mathematical difference is used. This compares byte values,
which may not be right for some languages.
When comparing a string with a number, the string is first converted to a
number. This is a bit tricky, because when a string doesn't look like a
number, the number zero is used. Example:
:if 0 == "one"
: echo "yes"
:endif
This will echo "yes", because "one" doesn't look like a number, thus it is
converted to the number zero.
For strings there are two more items:
a =~ b
a !~ b
matches with
does not match with
The left item "a" is used as a string. The right item "b" is used as a
pattern, like what's used for searching. Example:
:if str
: echo
:endif
:if str
: echo
=~ " "
"str contains a space"
!~ '\.$'
"str does not end in a full stop"