Go to the first, previous, next, last section, table of contents.
Here are some other commands that find matches for a regular expression.
They all operate from point to the end of the buffer.
- M-x occur RET regexp RET
-
Display a list showing each line in the buffer that contains a match for
regexp. A numeric argument specifies the number of context lines
to print before and after each matching line; the default is none.
To limit the search to part of the buffer, narrow to that part
(see section Narrowing).
If regexp contains upper-case letters, then the matching is done
in a case-sensitive way. Otherwise,
case-fold-search
controls
whether case is ignored.
The buffer `*Occur*' containing the output serves as a menu for
finding the occurrences in their original context. Click Mouse-2
on an occurrence listed in `*Occur*', or position point there and
type RET; this switches to the buffer that was searched and
moves point to the original of the chosen occurrence.
- M-x list-matching-lines
-
Synonym for M-x occur.
- M-x count-matches RET regexp RET
-
Print the number of matches for regexp after point.
- M-x flush-lines RET regexp RET
-
Delete each line that follows point and contains a match for
regexp.
- M-x keep-lines RET regexp RET
-
Delete each line that follows point and does not contain a match
for regexp.
In addition, you can use grep
from Emacs to search a collection
of files for matches for a regular expression, then visit the matches
either sequentially or in arbitrary order. See section Searching with Grep under Emacs.
Go to the first, previous, next, last section, table of contents.