‘M-x kill-matching-lines’ will prompt for a regular expression and then kill all the lines into a single entry in the kill ring.
(defun kill-matching-lines (regexp &optional rstart rend interactive) "Kill lines containing matches for REGEXP. See `flush-lines' or `keep-lines' for behavior of this command. If the buffer is read-only, Emacs will beep and refrain from deleting the line, but put the line in the kill ring anyway. This means that you can use this command to copy text from a read-only buffer. \(If the variable `kill-read-only-ok' is non-nil, then this won't even beep.)" (interactive (keep-lines-read-args "Kill lines containing match for regexp")) (let ((buffer-file-name nil)) ;; HACK for `clone-buffer' (with-current-buffer (clone-buffer nil nil) (let ((inhibit-read-only t)) (keep-lines regexp rstart rend interactive) (kill-region (or rstart (line-beginning-position)) (or rend (point-max)))) (kill-buffer))) (unless (and buffer-read-only kill-read-only-ok) ;; Delete lines or make the "Buffer is read-only" error. (flush-lines regexp rstart rend interactive)))