Return to the Essence of Text Editing

Erase Buffer

Some Emacs users find themselves wondering what’s the fastest way to
erase the contents of a buffer. As you know, I’m fond of
delete-selection-mode
and I find the combination of C-x h (mark-whole-buffer) + inserting
anything afterwards pretty potent.

Another pretty quick way to erase a buffer would be the built-in
erase-buffer command. It’s disabled by default since it’s considered
that beginners find it confusing(although I’m not sure why), so you’ll
be prompted to enable it the first time you run M-x
erase-buffer. Alternative you can simply put this snippet in your
config:

12

;; enable erase-buffer command(put'erase-buffer'disablednil)

You should note that any narrowing restrictions would have no effect
over erase-buffer and the buffer would be truly empty after invoking
the command. Conversely - narrowing has an effect over
mark-whole-buffer.

If you like the command you might want to bind it to some keybinding like C-c E: