Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Vim, I often find myself performing one search immediately followed by another search. I am wondering if I can combine the two searches into one command.

For example, if I want to find the first instance of the foobar variable within a function named transmogrify, I would enter:

/def transmogrify
/foobar

Or if I'm in a log file and I want to search for an error that happened after a specific date:

/2012-07-26
/ERROR

Is there a better way to do this? And no, I'm not looking to record a macro.

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

Easiest might be, e.g.

/def transmogrify/;/foobar
share|improve this answer
add comment

You can use the | symbol to do an OR operation when searching.

Taking your second example, for example:

/2012-07-26\|ERROR

Even better, if you have these set in your vimrc:

" Make search expressions "very magic"
nnoremap / /\v
vnoremap / /\v

Then you don't have to escape the |. E.g.:

/\v2012-07-26|ERROR
share|improve this answer
1  
In my brain that wouldn't work because it should stop once it finds the first term because that makes the whole statement true, but in real life it probably does work. –  Rob Jul 26 '12 at 15:53
    
@Rob is right; this didn't work when I just tested it. Thanks, though! –  arussell84 Jul 26 '12 at 15:56
    
It sort of works. It will get you what you want, you'll have to navigate through all the foobar or error though. It doesn't not work because of what I said, but because it matches both terms, which is what the | is for here. –  Rob Jul 26 '12 at 15:59
    
Yes, I see what you mean. I misunderstood what you were asking for. –  kenny Jul 26 '12 at 16:02
add comment

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.