5

How in vim/vi can I search for all lines that contain string1 and string2, where either string can appear anywhere on the line separated by whitespace and possibly other words?

I would also like to know how to do this using the less pager search (/).

0

1 Answer 1

4

Find two words in either order in a line:

/.*red\&.*blue

or

/\(red.*blue\)\|\(blue.*red\)

Other tools use a slightly different regular expression dialect; in less, you'd use:

/(red.*blue|blue.*red)
3
  • Looks good, where is less' regex syntax documented? Aug 7, 2013 at 16:13
  • I think it just uses man 7 regex. Aug 7, 2013 at 16:23
  • You also have \v, that is, /\v(red|blue).
    – Weekend
    May 19, 2020 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .