I would like to list the matches, when I hit:
/example
so that I see where all matches are at once.
I would like to list the matches, when I hit:
/example
so that I see where all matches are at once.
Setting hlsearch
will highlight all the matches in yellow allowing you to scan the file easily for matches. That may not be what you want though, after searching, :g//p will give you the listed matches
:g//p
In it's 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.
To elaborate on this ... instead of
/example
:g//p
you can also write directly
:g/example/p
or, as p(rint) is the default action for the :g(lobal) command, this can be shortened to
:g/example
And instead of p(rint), other actions are possible, e.g. d(elete). See :help :global
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