5

Is there a way to remove blank lines from a region of code I select?

I am asking because I copy/pasted code and it seems to have several blank lines I want to get rid off.

Drew
  • 75,699
  • 9
  • 109
  • 225
Billal Begueradj
  • 345
  • 1
  • 5
  • 18

1 Answers1

6
  1. Select what you want to change, or C-x h to select the whole buffer.
  2. Then: M-x flush-lines RET followed by ^$ RET or ^[[:space:]]*$ RET

^[[:space:]]*$ contain the meta-characters:

  • ^ for beginning of string,
  • $ for end of string,
  • [[:space:]]* zero or more spaces.

Ergo, if the first two meta-characters are next to each other or if there is one or more spaces between them, it must be a blank line. Source

You may eventually be interested by shrink-whitespace

Nsukami _
  • 6,341
  • 2
  • 22
  • 35