Home Explore Blog CI



neovim

4th chunk of `runtime/doc/usr_41.txt`
2b7fae9dcaa8b6c67f7508d533fb66ff413c4e6ff561cf050000000100000fa1
	\<C-W>		CTRL-W

The last two are just examples.  The  "\<name>" form can be used to include
the special key "name".
   See |expr-quote| for the full list of special items in a string.

==============================================================================
*41.3*	Expressions

Vim has a rich, yet simple way to handle expressions.  You can read the
definition here: |expression-syntax|.  Here we will show the most common
items.
   The numbers, strings and variables mentioned above are expressions by
themselves.  Thus everywhere an expression is expected, you can use a number,
string or variable.  Other basic items in an expression are:

	$NAME		environment variable
	&name		option
	@r		register

Examples: >

	:echo "The value of 'tabstop' is" &ts
	:echo "Your home directory is" $HOME
	:if @a > 5

The &name form can be used to save an option value, set it to a new value,
do something and restore the old value.  Example: >

	:let save_ic = &ic
	:set noic
	:/The Start/,$delete
	:let &ic = save_ic

This makes sure the "The Start" pattern is used with the 'ignorecase' option
off.  Still, it keeps the value that the user had set.  (Another way to do
this would be to add "\C" to the pattern, see |/\C|.)


MATHEMATICS

It becomes more interesting if we combine these basic items.  Let's start with
mathematics on numbers:

	a + b		add
	a - b		subtract
	a * b		multiply
	a / b		divide
	a % b		modulo

The usual precedence is used.  Example: >

	:echo 10 + 5 * 2
<	20 ~

Grouping is done with parentheses.  No surprises here.  Example: >

	:echo (10 + 5) * 2
<	30 ~

Strings can be concatenated with ".." (see |expr6|).  Example: >

	:echo "foo" .. "bar"
<	foobar ~

When the ":echo" command gets multiple arguments, it separates them with a
space.  In the example the argument is a single expression, thus no space is
inserted.

Borrowed from the C language is the conditional expression:

	a ? b : c

If "a" evaluates to true "b" is used, otherwise "c" is used.  Example: >

	:let i = 4
	:echo i > 5 ? "i is big" : "i is small"
<	i is small ~

The three parts of the constructs are always evaluated first, thus you could
see it work as:

	(a) ? (b) : (c)

==============================================================================
*41.4*	Conditionals

The ":if" commands executes the following statements, until the matching
":endif", only when a condition is met.  The generic form is:

	:if {condition}
	   {statements}
	:endif

Only when the expression {condition} evaluates to true (non-zero) will the
{statements} be executed.  These must still be valid commands.  If they
contain garbage, Vim won't be able to find the ":endif".
   You can also use ":else".  The generic form for this is:

	:if {condition}
	   {statements}
	:else
	   {statements}
	:endif

The second {statements} is only executed if the first one isn't.
   Finally, there is ":elseif":

	:if {condition}
	   {statements}
	:elseif {condition}
	   {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.  These are the most often used
ones:

	a == b		equal to
	a != b		not equal to
	a >  b		greater than
	a >= b		greater than or equal to
	a <  b		less than
	a <= b		less than or equal to

The result is one if the condition is met and zero otherwise.  An example: >

	:if v:version >= 700
	:  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

Title: Vim Expressions, Mathematics, Conditionals, and Logic Operations
Summary
This section covers expressions in Vim, including environment variables, options, and registers, with examples. It details mathematical operations like addition, subtraction, multiplication, division, and modulo. String concatenation with '..' is explained, along with conditional expressions 'a ? b : c'. The ':if', ':else', and ':elseif' commands for conditional execution are described. Finally, it outlines logic operations such as '==', '!=', '>', '>=', '<', and '<=', providing an example of using 'v:version' to check the Vim version.