GNU Emacs Manual - Appending Kills

Go to the first, previous, next, last section, table of contents.

### Appending Kills

Normally, each kill command pushes a new entry onto the kill ring. However, two or more kill commands in a row combine their text into a single entry, so that a single `C-y` yanks all the text as a unit, just as it was before it was killed.

Thus, if you want to yank text as a unit, you need not kill all of it with one command; you can keep killing line after line, or word after word, until you have killed it all, and you can still get it all back at once.

Commands that kill forward from point add onto the end of the previous killed text. Commands that kill backward from point add text onto the beginning. This way, any sequence of mixed forward and backward kill commands puts all the killed text into one entry without rearrangement. Numeric arguments do not break the sequence of appending kills. For example, suppose the buffer contains this text:

    This is a line -!-of sample text.

with point shown by -!-. If you type `M-d M-`DEL` M-d M-`DEL``, killing alternately forward and backward, you end up with ``a line of sample'` as one entry in the kill ring, and ``This is text.'` in the buffer. (Note the double space, which you can clean up with `M-`SPC`` or `M-q`.)

Another way to kill the same text is to move back two words with `M-b M-b`, then kill all four words forward with `C-u M-d`. This produces exactly the same results in the buffer and in the kill ring. `M-f M-f C-u M-`DEL`` kills the same text, all going backward; once again, the result is the same. The text in the kill ring entry always has the same order that it had in the buffer before you killed it.

If a kill command is separated from the last kill command by other commands (not just numeric arguments), it starts a new entry on the kill ring. But you can force it to append by first typing the command `C-M-w` (`append-next-kill`) right before it. The `C-M-w` tells the following command, if it is a kill command, to append the text it kills to the last killed text, instead of starting a new entry. With `C-M-w`, you can kill several separated pieces of text and accumulate them to be yanked back in one place.

A kill command following `M-w` does not append to the text that `M-w` copied into the kill ring.

Go to the first, previous, next, last section, table of contents.