8

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!

Srikanth
  • 11,780
  • 23
  • 72
  • 92

2 Answers2

10

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
  • 15,201
  • 3
  • 40
  • 47
  • okay so I tested it for you /search_pattern\%>16l\%<256l will find the word search_pattern between 16 & 256. The % sign means search all text and the >lessthan –  Feb 03 '10 at 14:25
  • 6
    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 Feb 03 '10 at 14:53
  • @jhwist +1, that's certainly easier for me to remember! – technomalogical Feb 03 '10 at 18:51
  • @jhwist Easier to remember, but it doesn't work :) This is the error I'm getting: "E486: Pattern not found: gc" – Srikanth Feb 04 '10 at 10:48
  • 2
    @vito. Oops, sorry, there is an 's' missing. It's supposed to read `:.,300s/foo//gc` – jhwist Feb 04 '10 at 12:01
  • @jhwist: what does 's' in `:.,300s` stand for? – Anurag Peshne May 21 '15 at 11:33
0

Adapting @jhwist solution, I find it easier to use markers remember to say 'n' to changes and not to go off the end

 :'a,'bs/extrascost//gc 
zzapper
  • 4,743
  • 5
  • 48
  • 45