Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 (/).

share|improve this question
    
/string1\|string2 within vi/vim –  val0x00ff Aug 7 '13 at 15:58
    
also set this :set hlsearch incsearch –  Rahul Patil Aug 7 '13 at 16:08
    
@val0x00ff That does not seem to work. –  Gregg Leventhal Aug 7 '13 at 16:16

1 Answer 1

up vote 2 down vote accepted

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)
share|improve this answer
    
Looks good, where is less' regex syntax documented? –  Gregg Leventhal Aug 7 '13 at 16:13
    
I think it just uses man 7 regex. –  Ingo Karkat Aug 7 '13 at 16:23
    
Thanks a lot! Accepted. –  Gregg Leventhal Aug 7 '13 at 19:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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