tags:

views:

530

answers:

5

I would like to list the matches, when I hit:

/example

so that I see where all matches are at once.

+7  A: 

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

Kevin
Should be ':set hlsearch' not ':hlsearch'.
too much php
+16  A: 

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

too much php
+1 for awesome trivia!!!
manifest
+2  A: 

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

+3  A: 

You can also do a :

g/pattern/#

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

Taurus Olson
+2  A: 

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

Paul Ivanov