tags:

views:

204

answers:

3

I want to have a similar tool in Emacs as the following in Vim

 :g/search/

to get a list of matches.

How can you get a list of matches in Emacs?

+14  A: 

M-x occur ?

http://www.impernix.com/Manuals/emacs/Other-Repeating-Search.html

LB
Thank you for your answer!
Masi
no problem...I'm a vi guy that sometimes has to use emacs...
LB
+4  A: 

My usual workflow is not to get a list and choose (don't know how to do that), but to use the incremental search:

C-s <search target>

gets the fist match after the point. If you don't like it another C-s gets the next one. Continue until you're happy (you'll need an extra C-s to wrap around from the and of the buffer). New enough emacsen can also highlight all the matches that are visible.

As noted in the comments by Török Gábor, this is the typical keybinding of isearch-forward. In the event that your bindings are different, you need to modify the prescribed procedure.

dmckee
`isearch-forward` (i.e. `C-s`) also allows you to type `C-o` after the given search phrase, and then it runs `occur` what LB suggested. This way you can use their power at once.
Török Gábor
Thanks, Török. One more thing I didn't know about emacs.
dmckee
This doesn't seem to work for me -- `C-o` is bound to `open-line`.
Rene Saarsoo
+5  A: 

In addition to M-x occurr check also M-x grep. This works in several files at once.

dfa
`rgrep` is even better as it allows recursive search.
Török Gábor