Usage:
/test evaluates the expression and returns its integer value, also setting the special variable %? (applying normal expression string-to-integer conversion if necessary). A new variable scope is NOT created.
Named variables may be accessed by simply using their name (with no leading '%'). This is called a variable reference.
Variable substitutions of the form "{var}" and "{var-default}" (with no leading '%') may be used to access any variable (named or positional).
Variable substitutions beginning with '%' may also be used, but are not recommended, as they can quickly get confusing if the /test is in a nested macro evaluation. The two methods described above are easier to use.
Before version 3.5, /test was frequently used as the condition of an /IF or /WHILE statement. This is no longer needed, since /IF and /WHILE can now take an expression as a condition.
/test can also be useful for evaluating
an expression for its side
effects, ignoring the return value. For example, the command
"/test
kbdel(kbpoint() - 1)
"
will perform a backspace, and
"/test regmatch('foo(.*)',
'foobar')
" will assign "bar" to %P1.
Another use for /test is to set the return value of a macro, since a macro's return value is that of the last command executed. For example:
/def isalnum = /test {*} =/ "[a-z0-9]"Side note: If this were written using a %-variable-substitution, like:
/def isalnum = /test "%*">%{*}" =/ "[a-z0-9]"and then /isalnum were called with a quote (") as an argument, the body would expand to this:
/test """ =/ "[a-z0-9]"which would cause an expression error. On the other hand, the {}-variable-reference is not evaluated by the macro expansion, but by the expression itself, so it does what is expected.
See: /if, /while, expressions, evaluation, variables