18

In an emacs buffer when editing a file called "log/development.log" how do I quickly remove all lines containing the word "Render"

1 Answer 1

31

You can go to beginning of buffer with M-<, then M-x flush-lines, type your word and hit RET.

(flush-lines REGEXP &optional RSTART REND INTERACTIVE)

Delete lines containing matches for REGEXP. When called from Lisp (and usually when called interactively as well, see below), applies to the part of the buffer after point. The line point is in is deleted if and only if it contains a match for regexp starting after point.

flush-lines also has an alias ,delete-matching-lines which might be easier to remember for you.


You also have keep-lines (alias delete-non-matching-lines), which deletes all of the non-matching lines, keeping only those that match.

2
  • 2
    M-< (beginning-of-buffer) also works. And I think its alias delete-matching-lines is easier to remember for me.
    – xuchunyang
    Mar 22, 2018 at 17:27
  • How can I make emacs display all matched lines to be deleted for confirmation? This will make the action much safer. I know that if I type C-s M-o emacs will summarize all matched lines in another buffer for me, but this is a different command with M-x flush-lines, and I have to type the regex twice which may introduce typo. This is why I want a confirmation list.
    – Daniel
    Mar 17, 2023 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.