38

This is probably an incredibly simple question, but I did not find any answer so far (I must lack the right sources, and I don't know where to search in vim's help).

I have a condition and I would like it to include 'AND', like

if (condition1 .AND. condition2)
   "do what I want you to do
endif

but I couldn't find the syntax. Same thing for 'OR'.

0
41

Vimscript use C-like operators && and ||.

You can find description of their usage on :h expr2. Some important points mentioned by the doc are the following

You'll find that the operators can be concatenated and && takes precedence over ||, so

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

Is equivalent to

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

Also once the result is known, the expression "short-circuits", that is, further arguments are not evaluated. This is like what happens in C.

If you use:

if a || b

The expression will be valid even is b is not defined.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.