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?
M-x occur
?
From the manual:
M-x occur
Prompt for a regexp, and display a list showing each line in the buffer that contains a match for it. The text that matched is highlighted using the
match
face. To limit the search to part of the buffer, narrow to that part (see Narrowing). A numeric argumentn
specifies thatn
lines of context are to be displayed before and after each matching line. The default number of context lines is specified by the variablelist-matching-lines-default-context-lines
.In the
*Occur*
buffer, you can click on each entry, or move point there and typeRET
, to visit the corresponding position in the buffer that was searched.o
andC-o
display the match in another window;C-o
does not select it. Alternatively, you can use theC-x `
(next-error
) command to visit the occurrences one by one (see Compilation Mode).Typing
e
in the*Occur*
buffer switches to Occur Edit mode, in which edits made to the entries are also applied to the text in the originating buffer. TypeC-c C-c
to return to Occur mode.The command
M-x list-matching-lines
is a synonym forM-x occur
.
In addition to M-x occurr
check also M-x grep. This works in several files at once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With