M-x flush-lines ^$
deletes all blank lines in a buffer. However I only want to delete extra blank lines, that is if there are n consecutive blank lines I want to delete n-1 and keep one.
I know that delete-blank-lines does the job for the blank lines under the point, however I want a simple solution which works for the whole buffer.
Any ideas how to do this? Especially is it possible to modify the regex ^$ from my first example to match only the extra lines?
Move your cursor directly before the region you want to delete. Set a mark by pressing Ctrl-6 or Ctrl-^ . Move the cursor to the end of the region you want to delete and press Ctrl-k .
The d command in sed can be used to delete the empty lines in a file.
When you want to insert a new line of text before an existing line, you can do it by typing the new line of text, followed by RET .
C-x h M-x replace-regexp RET ^ C-q C-j C-q C-j + RET C-q C-j RET
which marks the whole buffer and replaces two or more blank lines with a single blank line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With