[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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:

9.1 Setting the Mark  Select a region of text by setting the Mark
9.2 Selecting Text with Mouse  
9.3 Operating on the Region  Various ways to operate on a selected text
9.4 Moving Text  
9.5 Accumulating Text  Accumulating Text from several buffers


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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 following commands:

C-SPC
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 mark.
C-<
This command will push the mark at the beginning of the buffer without changing the position of your cursor.
C->
This command will push the mark at the end of the buffer without changing the position of your cursor.
You can also give arguments to C-< or C->. See section `The Mark and the Region' in XEmacs User's Manual, for more information.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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 these steps:

  1. Move the mouse cursor over the character at the beginning of the region of text you want to select.
  2. Press and hold the left mouse button.
  3. 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.
  4. Release the left mouse button.
The selected region of text is highlighted.

See section `Selecting Text with the Mouse' in XEmacs User's Manual, for more information regarding the Mouse and additional mouse operations.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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:
C-y
This command will yank or paste the last killed text (yank).
M-w
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.
C-M-w
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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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 many buffers:

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:
 
Append to buffer: (default <buffer name>) 
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.
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.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on August, 3 2012 using texi2html