Previous: , Up: Search   [Contents][Index]


12.8 Other Search-and-Loop Commands

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

Print each line that follows point and contains a match for the specified regexp. A numeric argument specifies the number of context lines to print before and after each matching line; the default is none.

The buffer ‘*Occur*’ containing the output serves as a menu for finding occurrences in their original context. Find an occurrence as listed in ‘*Occur*’, position point there, and type C-c C-c; this switches to the buffer that was searched and moves point to the original of the same occurrence.

M-x list-matching-lines

Synonym for M-x occur.

M-x count-matches

Print the number of matches following point for the specified regexp.

M-x delete-non-matching-lines

Delete each line that follows point and does not contain a match for the specified regexp.

M-x delete-matching-lines

Delete each line that follows point and contains a match for the specified regexp.