Deleting Whitespace

A whole workout on deleting whitespace? It’s worth it…

You might want to start by enabling whitespace mode: M-x whitespace-mode

Let’s start with closing the gap between lines…

M-^      Join a line with the previous line
C-x C-o       Delete white space after current line up to next line.

What’s great about the above two commands is that the point can be anywhere on the line when you call them.

The next two commands aren’t quite so quick to use, the point needs to be in the whitespace you’re trying to delete.

M-SPACE   Delete all spaces but one between two characters
M-\            Delete all whitespace between two characters

Don’t forget the rectangle commands:

C-x r k      Kills the rectangle between the point and the mark.

Find out more about how to use that command in this workout.
Lastly, removing line breaks. Use

C-M-%  query replace regex
Use C-q C-m or C-q C-j to find the line breaks.

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s