To search for word
inside of the selection:
/\%Vwor\%Vd
\%V
matches with zero with if inside the visual selection. The second \%V
makes sure that the whole word
is inside of the selection. Otherwise it would also match when only the beginning is inside.
To search for word
outside of the selection:
/\%V\@!wor\%V\@!d
The selection matcher from above is negated with \@!
. Here again the same construct is needed at the end to make sure that not only the beginning but also the ending of the word are outside the selection.
This has one gotcha:
Since the pattern only states that the first and last character have to be outside the selection, word
would still be matched if the selection spanned only the or
. So to make sure that the full word is outside, one would need to add \%V\@!
before every character of the word.