Emacs: List Matching Lines

By Xah Lee. Date: . Last updated: .

List Matching Lines and Other Line Commands

Alt+x list-matching-linesAlt+s o】 (alias of occur)

List all lines in the current file that matches a Regex text pattern.

Alt+x copy-matching-lines

Copy lines that matches a regex pattern.

Alt+x count-matches (alias of how-many)

Count matching lines.

Alt+x kill-matching-lines

Copy and delete matching lines

Alt+x delete-matching-lines (alias of flush-lines)
  • Delete lines that match a Regex.
  • Works on text selection or starts at the line your cursor is on.
Alt+x delete-non-matching-lines (alias of keep-lines)

Delete non-matching lines.

Alt+x delete-duplicate-lines

Delete duplicated lines in text selection.

emacs list-matching-lines 2021-07-18
emacs list-matching-lines 2021-07-18

Clicking the line jumps to the match location.

List Lines in ALL Buffers

Alt+x multi-occur if you want to list lines in ALL buffers.

Emacs, Work on Lines

Emacs Find Replace

Emacs, Regular Expression in Interactive Commands