Deleting Text

Before you start practicing deletion commands, you might want to know the undo command, which is discussed fully later in this chapter. Typing C-x u will undo your last edit; typing it again will undo the edit before that one, and so on.

Emacs provides many ways to delete text. The simplest way to delete text is to press the DEL key, which deletes the character immediately to the left of the cursor. See Figure 2-3 for possible locations of the DEL key on your keyboard. DEL is easiest to define by what it does: it deletes the previous character. If you’re typing and you decide to erase the last character you typed, what key on your keyboard do you reach for? In Emacs, it’s the DEL key.

Emacs provides a number of other deletion commands—perhaps too many for your taste, although you’ll eventually find a reason to use most of them. For example, C-d (for delete-character) deletes the character under the cursor. The command for deleting the next word is ESC d (for kill-word). Once again, note how the ESC key augments the command: C-d operates on a character, and ESC d operates on a word.

Emacs has commands to delete the next or previous word, sentence, and paragraph. By their names, you can guess what they do when you’re between words, sentences, or paragraphs. If you’re in the middle of an entity, however, they do something a little surprising: they delete a portion of the current word, sentence or paragraph, backward or forward depending on whether the command deletes ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.