9. Selecting and Moving Text
Many Emacs commands operate on an arbitrary contiguous
part of the current buffer. You can select some part of the buffer and
edit only that part of the buffer. This selected buffer is called a
region. You can select text in two ways:
You use special keys to select text by defining a region between the
cursor and the mark (which you set).
If you are running XEmacs under X, you can also select text
with the mouse.
9.1 Setting the Mark
To define a region you need to set the mark at one end of it and
move the cursor to the other end. Once you set the mark, it remains
there until you set it again to some other place. Each buffer has its
own mark ring (a place where Emacs remembers 16 previous
locations of the mark). To set the mark, you can use the
You can also give arguments to C-< or C->. See section `The Mark and the Region' in XEmacs User's Manual, for more information.
- This command will set the mark at the position of your cursor
set-mark-command). You can move your cursor around and the
mark will stay there.
- C-x C-x
- Interchange mark and point (
exchange-point-and-mark). Since Emacs
will have only one cursor, after you move the cursor it will be unable
to show you where you set the the mark. In order to see the
mark you can type the command C-x C-x which will put your cursor
on the position of your mark and your mark on the position of your
cursor. Use the command again to reset the positions of your cursor and
- This command will push the mark at the beginning of the buffer without
changing the position of your cursor.
- This command will push the mark at the end of the buffer without
changing the position of your cursor.
9.2 Selecting Text with Mouse
If you are using XEmacs under X, you can use the mouse to select
text. The selected text will always be highlighted, so just by looking
at the text you know what you have selected so far. To select a word
just double-click with the left-mouse-button on the word. To select a
whole line triple-click anywhere on the line with the
left-mouse-button. You can also use the Copy item from the Edit
menu on the menu-bar to select text. This kind of selection is called
Clipboard selection, See section `X Clipboard Selection' in XEmacs User's Manual, for more information. To select an arbitrary region, follow
The selected region of text is highlighted.
Move the mouse cursor over the character at the beginning of the region of
text you want to select.
Press and hold the left mouse button.
While holding the left mouse button down, drag the cursor to the
character at the end of the region of text you want to select.
Release the left mouse button.
See section `Selecting Text with the Mouse' in XEmacs User's Manual, for
more information regarding the Mouse and additional mouse operations.
9.3 Operating on the Region
Once you have selected a region you can do a lot of things to the text
in the region:
Kill the text with C-w. For example if you want to kill a
paragraph, position the cursor to the beginning of the paragraph and
type C-SPC. Then go to the end of the paragraph and type
C-w. The entire paragraph will be deleted. You can also select the
text with a mouse and type C-w to kill the entire
region. See section `Killing' in XEmacs User's Manual, for more information.
Save the text in a buffer or a file (see section `Accumulating Text' in XEmacs User's Manual).
You can convert the case of the text with C-x C-l or C-x C-u
If you type C-x C-u the selected text will become all
upper-case. If you type C-x C-l the selected text will become all
Print hardcopy with M-x
print-region. See section `Hardcopy' in XEmacs User's Manual, for more
information. This command will print a hardcopy of only the selected
Indent it with C-x TAB or C-M-\
See section `Indentation' in XEmacs User's Manual, for more information.
9.4 Moving Text
The most common way to move or copy text in Emacs is through
killing or `cutting' it and then yanking or
`pasting' it. You can also use the Cut or Copy option from
the Edit menu for killing and copying respectively. See section 2.2.2 The Edit Menu,
for reviewing the commands for killing text. All the killed text
in Emacs is recorded in the kill ring. Since there is only one
kill ring in Emacs, you can kill text in one buffer and yank it in
another buffer. To `paste' or
`yank' the killed text you can use the following commands:
- This command will yank or paste the last killed text (
- Save region as last killed text without actually killing it
copy-region-as-kill). You can use this command to copy a
selected region and then yank (or paste) it without actually removing it
from the buffer.
- Append next kill to last batch of killed text
append-next-kill). This command will append whatever you killed
last to what you kill now. Then later you will be able to yank the
entire appended text from the kill ring.
9.5 Accumulating Text
The following commands can be used for accumulating text from
different buffers into one place or for copying one region of text into
- M-x append-to-buffer
- Append region to contents of specified buffer
append-to-buffer). After you type in this command and press
RET, Emacs will prompt you for a buffer name. You will see a
message in the echo area:
After you type in a buffer name, a copy of the region will be inserted
at the location of the cursor into that buffer. If there is no buffer
with the name given by you, Emacs will create a new buffer with that
name. By default the cursor's position in the <buffer name> is at the end.
Append to buffer: (default <buffer name>)
- M-x prepend-to-buffer
- Prepend region to contents of specified buffer. This command is similar
to the above command except that the cursor in the buffer (by default)
is at the beginning rather than at the end.
- M-x copy-to-buffer
- Copy region into specified buffer, deleting that buffer's old
contents. This command will also prompt you for a buffer name.
- M-x insert-buffer
- Insert contents of specified buffer into current buffer at point. This
command will prompt you for a buffer name which you want to be copied
into the current buffer at the location of the cursor.
- M-x append-to-file
- This command will prompt you for a filename and append the region to
the end of the contents of the specified file.
See section `Accumulating Text' in XEmacs User's Manual, for more
information regarding this topic.
You can also use rectangle commands for operating on rectangular
areas of text. See section `Rectangles' in XEmacs User's Manual, for more
information regarding rectangle commands.
Emacs also provides registers which serve as temporary storage for
text or positions. Each register has a one character name and they can
store regions, a rectangle, or a mark i.e. a cursor
position. Whatever you store in register stays there until you store
something else in that register. To find out about commands which
manipulate registers See section `Registers' in XEmacs User's Manual.
This document was generated
by XEmacs Webmaster on August, 3 2012