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-_ or C-x u undoes your last edit; typing undo again undoes 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-4 for possible locations of the Del key on your keyboard. It is sometimes referred to as the Backspace key. 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 do you reach for? That's the key Emacs refers to as Del.
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 M-d (for kill-word). Once again, note how the Meta key augments the command: C-d operates on a character, and M-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 ...
Get Learning GNU Emacs, 3rd 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.