48

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'.

statox
  • 49,782
  • 19
  • 148
  • 225
Feffe
  • 1,761
  • 2
  • 14
  • 21

1 Answers1

51

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.

statox
  • 49,782
  • 19
  • 148
  • 225