Emacs Redux

Return to the Essence of Text Editing

Delete Whitespace Around Point

| Comments

One task that often pops when editing text or code is the need to remove some extra whitespace around the point(the cursor). Emacs has your back!

First, we have the command delete-horizontal-space(bound to M-\) - it deletes all spaces and tabs around the point. With a prefix argument(C-u M-\) the command deletes only the whitespace before the point.

One similar, although a bit less known, command is just-one-space(bound to M-SPC) - it deletes all spaces and tabs around the point, leaving just one space (or N spaces if you supply N as a prefix argument like C-4 M-SPC). If N is negative, the command deletes newlines as well, leaving -N spaces.

One minor snafu with just-one-space is that M-SPC is a no-go on OSX since just about everyone uses it for quick access to Spotlight or switching between languages. You might want to use a different keybinding like this one:

1
(global-set-key (kbd "C-c j") 'just-one-space)

Personally, of the two commands I find just-one-space the more useful.

In Prelude just-one-space is additionally bound to the kk keychord.

Comments