Home Explore Blog CI



neovim

11th chunk of `runtime/doc/vimeval.txt`
9848db62fbaa8d7a7b5c8d1ac3683fddf1d723efc988f2c00000000100000fa4
 lnum == 1000 ? "last" : lnum

To keep this readable, using |line-continuation| is suggested: >
	:echo lnum == 1
	:\	? "top"
	:\	: lnum == 1000
	:\		? "last"
	:\		: lnum

You should always put a space before the ':', otherwise it can be mistaken for
use in a variable such as "a:1".

Falsy operator ~

This is also known as the "null coalescing operator", but that's too
complicated, thus we just call it the falsy operator.

The expression before the '??' is evaluated.  If it evaluates to
|truthy|, this is used as the result.  Otherwise the expression after the '??'
is evaluated and used as the result.  This is most useful to have a default
value for an expression that may result in zero or empty: >
	echo theList ?? 'list is empty'
	echo GetName() ?? 'unknown'

These are similar, but not equal: >
	expr2 ?? expr1
	expr2 ? expr2 : expr1
In the second line "expr2" is evaluated twice.


------------------------------------------------------------------------------
expr2 and expr3						*expr2* *expr3*

expr3 || expr3 ..	logical OR		*expr-barbar*
expr4 && expr4 ..	logical AND		*expr-&&*

The "||" and "&&" operators take one argument on each side.  The arguments
are (converted to) Numbers.  The result is:

    input			 output ~
n1	n2		n1 || n2	n1 && n2 ~
|FALSE|	|FALSE|		|FALSE|		|FALSE|
|FALSE|	|TRUE|		|TRUE|		|FALSE|
|TRUE|	|FALSE|		|TRUE|		|FALSE|
|TRUE|	|TRUE|		|TRUE|		|TRUE|

The operators can be concatenated, for example: >

	&nu || &list && &shell == "csh"

Note that "&&" takes precedence over "||", so this has the meaning of: >

	&nu || (&list && &shell == "csh")

Once the result is known, the expression "short-circuits", that is, further
arguments are not evaluated.  This is like what happens in C.  For example: >

	let a = 1
	echo a || b

This is valid even if there is no variable called "b" because "a" is |TRUE|,
so the result must be |TRUE|.  Similarly below: >

	echo exists("b") && b == "yes"

This is valid whether "b" has been defined or not.  The second clause will
only be evaluated if "b" has been defined.


------------------------------------------------------------------------------
expr4							*expr4*

expr5 {cmp} expr5

Compare two expr5 expressions, resulting in a 0 if it evaluates to false, or 1
if it evaluates to true.

			*expr-==*  *expr-!=*  *expr->*	 *expr->=*
			*expr-<*   *expr-<=*  *expr-=~*  *expr-!~*
			*expr-==#* *expr-!=#* *expr->#*  *expr->=#*
			*expr-<#*  *expr-<=#* *expr-=~#* *expr-!~#*
			*expr-==?* *expr-!=?* *expr->?*  *expr->=?*
			*expr-<?*  *expr-<=?* *expr-=~?* *expr-!~?*
			*expr-is* *expr-isnot* *expr-is#* *expr-isnot#*
			*expr-is?* *expr-isnot?*
		use 'ignorecase'    match case	   ignore case ~
equal			==		==#		==?
not equal		!=		!=#		!=?
greater than		>		>#		>?
greater than or equal	>=		>=#		>=?
smaller than		<		<#		<?
smaller than or equal	<=		<=#		<=?
regexp matches		=~		=~#		=~?
regexp doesn't match	!~		!~#		!~?
same instance		is		is#		is?
different instance	isnot		isnot#		isnot?

Examples:
"abc" ==# "Abc"	  evaluates to 0
"abc" ==? "Abc"	  evaluates to 1
"abc" == "Abc"	  evaluates to 1 if 'ignorecase' is set, 0 otherwise

							*E691* *E692*
A |List| can only be compared with a |List| and only "equal", "not equal",
"is" and "isnot" can be used.  This compares the values of the list,
recursively.  Ignoring case means case is ignored when comparing item values.

							*E735* *E736*
A |Dictionary| can only be compared with a |Dictionary| and only "equal", "not
equal", "is" and "isnot" can be used.  This compares the key/values of the
|Dictionary| recursively.  Ignoring case means case is ignored when comparing
item values.

							*E694*
A |Funcref| can only be compared with a |Funcref| and only "equal", "not
equal", "is" and "isnot" can be used.  Case is never ignored.  Whether
arguments or a Dictionary are bound (with a partial) matters.  The
Dictionaries must also be equal (or the same, in case of "is") and the
arguments must be equal (or the same).

To compare Funcrefs to see if they

Title: Vim Expression Syntax: Falsy Operator, Logical Operators, and Comparison Operators
Summary
This section describes the falsy operator (`??`) and how it differs from the ternary operator. It then explains the logical OR (`||`) and logical AND (`&&`) operators, including their short-circuiting behavior and precedence. Finally, it details the comparison operators (`==`, `!=`, `>`, `>=`, `<`, `<=`, `=~`, `!~`, `is`, `isnot`) and their case-sensitive (`#`) and case-insensitive (`?`) variants. It covers how these operators work with strings, lists, dictionaries, and funcrefs.