16

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

american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40

1 Answers1

29

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
mkcms
  • 1,340
  • 12
  • 13
  • 2
    `M-<` (`beginning-of-buffer`) also works. And I think its alias `delete-matching-lines` is easier to remember for me. – xuchunyang Mar 22 '18 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 '23 at 04:36