killing text. The primary difference between the two is that
"killed" things can be brought ("yanked") back, and "deleted" things cannot.
All "killed" text from all files (running on the same emacs session) is stored
in the same area so you can use kill
to move text from one file to
another. In this respect kill and "yank" are very similar to "cut"
and "paste" on a Mac or PC.
When you put something into the kill ring it does not delete the prior
entry. When you bring it back ("yank" it) the prior item will be waiting to be
brought back next. While there are many similarities to "killing" and
"yanking" in emacs
and "cutting" and "pasting" on a
PC
or Mac, this is a major difference. If you wish to
cut text and then paste it to several places you must use the copy
command described below. If you try to cut the text once and paste it to
several places, you will be very disappointed by the result.
Because emacs can be used without a mouse, there are several commands to
allow you to kill different quantities of text. A few basic kill
commands are:
M-[Del] kill the word immediately before the cursor
M-d kill the word after the cursor
C-k kill from the cursor position to the end of line
To bring the killed text back use the "yank" command C-y
.
As long as you keep repeating the same kill command, all text
deleted will be considered to be from the same kill and will be stored
as one unit. For instance, if you kill three lines in a row, a single
"yank" command will bring all three lines back.
Another way to kill text, which might seem more familiar, is to
mark the location at which you want to begin the kill with the
"mark" command, C-@
or C-[space bar]
, and go to the
other end and enter C-w
. The advantage of using this method is
that you can quickly delete a region of text. To do this, first move the
cursor over to the location at which you want to begin. Type C-@
to set the marker in place. Now move over to the other end of the text block
and type C-w
to kill the text.
You can copy a region or section of text the same way as described above,
but use the M-w
command instead of the C-w
command.
The copy command is similar to the kill command except it
stores the text without deleting it.
If you kill more than one thing, you may want to retrieve an
early item without retrieving you last item. If so, you can use the command
M-y
. This command scrolls though the kill ring until you find the
kill you are looking for. If you follow your "yank" command, C-y
,
with the command M-y
you will get the second to last thing
"killed". If you continue to use the command M-y
you will scroll
through all of your previous "kills". Keep in mind that wherever you stop is
reset as the most recent kill.
If you accidentally kill something, you have two options. You can
use the undo command, C-x u
or if you have not moved yet, you can
"yank" your text back by using C-y
.
Try some killing
and yanking
(put the file in
random order, perhaps?) before you start the next section.