Searches in Neovim Ranges


range expressions can also reference lines that match a specified pattern. As with searching in other contexts, / is used for forward search, and ? is used for backwards searches. Use patterns with the format:

[line]/{pattern}/

or

[line]?pattern?

where line specifies which line to start searching from (default the current line), and {pattern} is the pattern to search for. When specified, line can be an absolute number, or another expression that evaluates to a line number.

For example, the range of lines between the first line that matches /find/ and line 5 is given by:

:/find/,5
Prior to Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
COMMANDTop1:1
:/find/,5yank a
After Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMALTop1:1
3 lines yanked into "a
Confirm Register Content
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMALTop1:1
 
:reg aType Name Content  l  "a   for, that he is unable to find anything, to let anything enter hism

As expected, Step 2 indicates that we yanked 3 lines, and Step 3 indicates that the selection started with the line matching /find/.

Suppose we wanted to skip a few lines of text before starting the search. For example, if we are editing a markdown document that contains meta information at the top of the file we may want to skip that content then search only the body text. If we know that the meta information is 3 lines long, the following range expression could be used:

:4/find/,$
Prior to Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
COMMANDTop1:1
:4/find/,$yank b
After Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMALTop1:1
4 lines yanked into "b
Confirm Register Content
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMALTop1:1
 
:reg bType Name Content  l  "b   means: having a goal. But finding means: being free, being open, havi

Rather than starting the search from a fixed line, we can specify the starting line as a pattern as well. This allows us to search the buffer for a specific condition, then search for the pattern that will start the range, then proceed to the end of the range. For example, to start from the line matching /anything/, then search for the first line matching /obsessed/ and include lines until the first line matching /venerable/ we could use the following:

:/anything//obsessed/,/venerable/
Prior to Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
COMMANDTop1:1
:/anything//obsessed/,/venerable/yank c
After Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMALTop1:1
3 lines yanked into "c
Confirm Register Content
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMALTop1:1
 
:reg cType Name Content  l  "c   because he has a goal, because he is obsessed by the goal. Searching

You can also search backwards from the line containing the cursor. For example, if the cursor is on line 4 and you want the range of lines between the first preceding line that matches search and the current line:

:?search?,.
Prior to Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
COMMAND40%4:1
:?search?,.yank d
After Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMAL40%4:1
3 lines yanked into "d
Confirm Register Content
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMAL40%4:1
 
:reg dType Name Content  l  "d   happen that the only thing his eyes still see is that what he searche

and finally, the range of lines between the first preceding line that matches search and the next line that matches venerable:

:?search?,/venerable/
Prior to Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
COMMAND40%4:1
:?search?,/venerable/yank e
After Execution
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMAL40%4:1
6 lines yanked into "e
Confirm Register Content
"When·someone·is·searching,"·said·Siddhartha,·"then·it·might·easily
happen·that·the·only·thing·his·eyes·still·see·is·that·what·he·searches
for,·that·he·is·unable·to·find·anything,·to·let·anything·enter·his
mind,·because·he·always·thinks·of·nothing·but·the·object·of·his·search,
because·he·has·a·goal,·because·he·is·obsessed·by·the·goal.·Searching
means:·having·a·goal.·But·finding·means:·being·free,·being·open,·having
no·goal.·You,·oh·venerable·one,·are·perhaps·indeed·a·searcher,·because,
striving·for·your·goal,·there·are·many·things·you·don't·see,·which·are
directly·in·front·of·your·eyes."
NORMAL40%4:1
 
:reg eType Name Content  l  "e   happen that the only thing his eyes still see is that what he searche