I know that with Vim's substitution command you can specific a range of lines:
:12,24s/search/replace
I want to be able to specify a range with normal searches as well. Something like
:12,24/search
Since that doesn't seem to work (at least on my Vim configuration), does anybody know how to achieve this?
Thank you.
and then
so essentially:
Great answer from akira. But after some digging, I found an alternative. It's not as elegant but easier to type in:
This will give you one annoying prompt but it will end up on the first line within the range containing the sought string.
Do you really need line numbers? Another way could be to select the range visually.
/\%Vwhat_to_search
to search for 'what_to_search' in the previously selected range.This is lesser to type, but not directly what you have asked for ;-)
See :help %V
[EDIT] Great, I have just learned that the range to search in can be changed after doing the search by selecting another range, unselecting this range again by pressing ESC and pressing n to repeat search. Vim is really always good for pleasant surprises.
Keep using the substitution command, but append the
gc
flags to your original example.:12,24s/search//gc
From
:help search-range
Example:
:.,300s/Pattern//gc
If there marks say a and b, then the search can be restricted to the region between a and b using
This can be simplified with a cmap
Using Narrow Region plugin we can open a temporary buffer with the range we need to search or change
Then we can meke a search
Or a change and write the buffer back
If you would like to search to the end of the file, use $:
This will search from 3-d line to the end