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.
The Vim goto line number command One can use the G letter. For example, press [ESC] key and type 10G (Shift-g) goto line number 10.
To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file. To look for the next occurrence after the first, either press n or press / again and then press Enter .
One can search forward in vim/vi by pressing / and then typing your search pattern/word. To search backward in vi/vim by pressing ? and then typing your search pattern/word. Once word found in vim, you can press the n key to go directly to the next occurrence of the word in backwards.
Great answer from akira. But after some digging, I found an alternative. It's not as elegant but easier to type in:
:12,24g/search/
This will give you one annoying prompt but it will end up on the first line within the range containing the sought string.
:help search-range
and then
:help /\%>l
so essentially:
/\%>12l\%<24lsearch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With