Suppose that I have marks 'a and 'b, and I want to search for all occurrences of foo between them.

The ex command


will replace only between 'a and 'b. Is there any command like


that will find foo only between those two marks? (That exact syntax does something, but I can't figure out what. It doesn't seem to be what I want.)


You can use \%>'m and \%<'m to match after and before a given mark, m.


For more helps see:

:h /\%'m
| improve this answer | |
  • Thank you! And then some more characters. – LSpice Mar 15 '18 at 18:06
  • Do you know what my imaginary syntax :'a,'b/foo is doing? The effect that I observe is that I jump to some other part of the document, way outside the mark-delimited region, but I can't figure out why I'm going there. – LSpice Mar 15 '18 at 18:08
  • 1
    'a,'b is a range. So you can actually type this out as it to see what it does: :'a,'b. It will move to the 'b position as that is the end of the range. You then execute a command, e.g. /. So it searches for foo after line 'b. For more help see :h :range – Peter Rincker Mar 15 '18 at 18:11
  • Ah, I didn't realise that I was inadvertently concatenating two commands. Thanks! – LSpice Mar 15 '18 at 18:40
  • @LSpice, see if you can learn how this one works: :'a,'b/hello/d "delete from the line of mark a through the first line containing the word hello after the line of mark b" – Mass Mar 15 '18 at 19:17

FWIW: :'a,'bs/foo//n substitute foo with nothing and choose 'no' when asked for the replacement. afterwards just hit the next (n) to get to the next occurrence.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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