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

Solution 1:

: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.

Solution 2:

You can also do a :

g/pattern/#

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

Solution 3:

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

Solution 4:

Just learned a new one: the Location List!
Type :lvim foo % to search for foo in the current file and enter all matches containing foo into the location list.
Type :lopen to open the location list in the quickfix window, which is fully navigable as usual.
Use :lnext/:lprevious to to through the list (use tpope/unimpaired mappings for the best experience)