How can you list the matches of Vim's search?

:g//p

In its longer form:

:global/regular-expression/print

You can leave out the pattern/regex and Vim will re-use the previous search term.

Trivia: The grep tool was named after this command sequence.


You can also do a :

g/pattern/#

that will print the pattern you want and the number of the line.


if you want to look at this list and jump quickly between the matches, consider using

:vimgrep example %

or

:grep example %

This will populate the "error list" with all of the matches so that you can use :copen to list them all in the quickfix buffer, press enter on a particular line to jump to that match, or use commands like :cn and :cp to go back and forth.

for a thorough explanation, see my reply to a similar question

Tags:

Vim

Search