Next: , Previous: Mark, Up: Top


12 Killing and Moving Text

Killing means erasing text and copying it into the kill ring, from which you can bring it back into the buffer by yanking it. (Some applications use the terms “cutting” and “pasting” for similar operations.) This is the most common way of moving or copying text within Emacs. It is very versatile, because there are commands for killing many different types of syntactic units.

Most commands which erase text from the buffer save it in the kill ring. These are known as kill commands. The kill ring stores several recent kills, not just the last one, so killing is a very safe operation: when you make a new kill, you don't have to worry much about losing text that you previously killed.

You can yank text from the kill ring into any position in a buffer, including a position in a different buffer; the kill ring is shared by all buffers. The C-/ (undo) command can undo both kill and delete commands (see Undo); the importance of the kill ring is that you can yank the text in a different place.

Commands that erase text but do not save it in the kill ring are known as delete commands. These include C-d (delete-char) and <DEL> (delete-backward-char), which delete only one character at a time, and those commands that delete only spaces or newlines. Commands that can erase significant amounts of nontrivial data generally do a kill operation instead. The commands' names and individual descriptions use the words ‘kill’ and ‘delete’ to say which kind of operation they perform.

Some specialized buffers contain read-only text, which cannot be modified and therefore cannot be killed. But some users like to use the kill commands to copy read-only text into the kill ring, without actually changing it. Therefore, the kill commands work specially in a read-only buffer: they move over text, and copy it to the kill ring, without actually deleting it from the buffer. Normally, kill commands beep and display an error message when this happens. But if you set the variable kill-read-only-ok to a non-nil value, they just print a message in the echo area to explain why the text has not been erased.

You can also use the mouse to kill and yank. See Cut and Paste.