views:

147

answers:

1

Find and replace scope can be limited like this:

:16,256s/search_term/replacement/gc

I don't want to replace my search term with any other text, I just want to find them. I tried the following, but it didn't help:

:16,256/search_term # Notice that there is no 's' here

Thanks for your time!

+5  A: 

From the vim documentation:

You can limit the search command "/" to a certain range of lines by including \%>l items. For example, to match the word "limit" below line 199 and above line 300: >

/\%>199l\%<300llimit

This means: Match below line 199 and before line 300 and find the word limit.

jhwist
Thanks. I wonder why it's so complicated, though.
artknish
vimdoc: http://vimdoc.sourceforge.net/htmldoc/pattern.html
You can also use `:.,300/foo//gc` and then hit 'q' to stop the match and then 'n' for the next match. Don't know if that's more convenient, though.
jhwist
@jhwist +1, that's certainly easier for me to remember!
technomalogical
@jhwist Easier to remember, but it doesn't work :) This is the error I'm getting: "E486: Pattern not found: gc"
artknish
@vito. Oops, sorry, there is an 's' missing. It's supposed to read `:.,300s/foo//gc`
jhwist
@jhwist Ah, thanks! Makes complete sense now.
artknish