Книга: Learning GNU Emacs, 3rd Edition

2.2.1 The Kill Ring

2.2.1 The Kill Ring

By now you may have noticed that some deletion commands in Emacs are called kill commands, such as kill-region, kill-word, and the like. In Emacs, killing is not fatal, but in fact, quite the opposite. Text that has been killed is not gone forever but is hidden in an area called the kill ring. The kill ring, though it sounds somewhat like a violent gang, is an internal storage area where Emacs puts things you've copied or deleted. Do not confuse the kill ring with the system clipboard, which allows for copying and pasting between applications. We'll cover how Emacs relates to the system clipboard later in this chapter.

You can get back what you've deleted by typing C-y (for yank).[12] Conveniently, if you kill several lines in succession, Emacs collects them into a single item and places the whole unit into the kill ring; a single C-y command will bring everything back. In the following example, we'll use C-k four times to delete the first two lines of A Tale of Two Cities. (Remember: the first C-k deletes the text; the second C-k deletes the remaining blank line.) Then we'll use a single C-y to bring everything back.

Initial state:


The cursor is in upper-left corner.

Type: C-k C-k C-k C-k


You have deleted the first two lines with C-k.

Type: C-y


You got everything back with a single command.

What exactly goes into the kill ring? Everything you delete with C-k in addition to everything you delete with C-w and everything you copy with M-w (two commands that you'll learn shortly) go into the kill ring. Words, sentences, and paragraphs that you delete with M-d, M-Del, and their relatives also go into the kill ring. In addition, text that you delete with C-u followed by either Del or C-d goes into the kill ring. About the only thing that Emacs doesn't save in the kill ring is single characters, deleted with Del or C-d. (If you need to, you can get this type of deletion back using the undo command, bound to both C-_ and C-x u.)

Emacs is clever about what it puts into the kill ring: when it is assembling a big block of text from a group of deletions, it always assembles the text correctly. For example, you can type a few M-d's, followed by some M-Del's, with a couple of C-k's thrown in. When you type C-y, Emacs yanks all the text that you've deleted in the proper order.

However, there's one thing you have to watch out for. Emacs stops assembling these blocks of text as soon as you give any command that isn't a kill command. For example, if you type C-k, then delete a single character with C-d, then type another C-k, you've broken the chain. Emacs doesn't consider deletion of a single character with C-d a "kill" command; it's just a deletion and it isn't stored. In this case, you haven't made a single chain of kill commands; you've made two chains. Later, we'll see how to get the older killed text back.

Table 2-3 summarizes the commands for deleting, killing, and yanking text, including options from the Edit menu.

Table 2-3. Deletion commands

Keystrokes Command name Action
C-d delete-char Delete character under cursor.
Del delete-backward-char Delete previous character.
M-d kill-word Delete next word.
M-Del backward-kill-word Delete previous word.
C-k kill-line Delete from cursor to end of line.
M-k kill-sentence Delete next sentence.
C-x Del backward-kill-sentence Delete previous sentence.
C-y yank Restore what you've deleted.
C-w Edit ? Cut kill-region Delete a marked region (see next section).
(none) kill-paragraph Delete next paragraph.
(none) backward-kill-paragraph Delete previous paragraph.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.214. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз