1 @comment node-name, next, previous, up
2 @node Select and Move, Search and Replace, Other Customizations, Top
3 @chapter Selecting and Moving Text
7 Many Emacs commands operate on an arbitrary contiguous
8 part of the current buffer. You can select some part of the buffer and
9 edit only that part of the buffer. This selected buffer is called a
10 @dfn{region}. You can select text in two ways:
14 You use special keys to select text by defining a region between the
15 cursor and @dfn{the mark} (which you set).
17 If you are running XEmacs under X, you can also select text
21 @comment node-name, next, previous, up
23 * Selecting Text:: Select a region of text by setting the Mark
24 * Mouse:: Selecting Text with Mouse
25 * Region Operation:: Various ways to operate on a selected text
26 * Moving Text:: Moving Text
27 * Accumulating text:: Accumulating Text from several buffers
30 @node Selecting Text, Mouse, Select and Move, Select and Move
31 @section Setting the Mark
36 @findex set-mark-command
37 @findex mark-beginning-of-buffer
38 @findex mark-end-of-buffer
39 @findex exchange-point-and-mark
40 To define a region you need to set @dfn{the mark} at one end of it and
41 move the cursor to the other end. Once you set the mark, it remains
42 there until you set it again to some other place. Each buffer has its
43 own @dfn{mark ring} (a place where Emacs remembers 16 previous
44 locations of the mark). To set @dfn{the mark}, you can use the
49 This command will set @dfn{the mark} at the position of your cursor
50 (@code{set-mark-command}). You can move your cursor around and @dfn{the
51 mark} will stay there.
53 Interchange mark and point (@code{exchange-point-and-mark}). Since Emacs
54 will have only one cursor, after you move the cursor it will be unable
55 to show you where you set the @dfn{the mark}. In order to see @dfn{the
56 mark} you can type the command @kbd{C-x C-x} which will put your cursor
57 on the position of your mark and your mark on the position of your
58 cursor. Use the command again to reset the positions of your cursor and
61 This command will push the mark at the beginning of the buffer without
62 changing the position of your cursor.
64 This command will push the mark at the end of the buffer without
65 changing the position of your cursor.
68 You can also give arguments to @kbd{C-<} or @kbd{C->}. @xref{The Mark
69 and the Region,,,xemacs,XEmacs User's Manual}, for more information.
71 @comment node-name, next, previous, up
72 @node Mouse, Region Operation, Selecting Text, Select and Move
73 @section Selecting Text with Mouse
74 @cindex mouse selection
75 @cindex clipboard selection
76 @cindex primary selection
78 If you are using XEmacs under X, you can use the mouse to select
79 text. The selected text will always be highlighted, so just by looking
80 at the text you know what you have selected so far. To select a word
81 just double-click with the left-mouse-button on the word. To select a
82 whole line triple-click anywhere on the line with the
83 left-mouse-button. You can also use the @b{Copy} item from the @b{Edit}
84 menu on the menu-bar to select text. This kind of selection is called
85 @b{Clipboard} selection, @xref{X Clipboard Selection,,,xemacs,XEmacs User's
86 Manual}, for more information. To select an arbitrary region, follow
91 Move the mouse cursor over the character at the beginning of the region of
92 text you want to select.
94 Press and hold the left mouse button.
96 While holding the left mouse button down, drag the cursor to the
97 character at the end of the region of text you want to select.
99 Release the left mouse button.
101 The selected region of text is highlighted.
103 @xref{Selecting Text with the Mouse,,,xemacs,XEmacs User's Manual}, for
104 more information regarding the Mouse and additional mouse operations.
106 @comment node-name, next, previous, up
107 @node Region Operation, Moving Text, Mouse, Select and Move
108 @section Operating on the Region
109 Once you have selected a region you can do a lot of things to the text
120 Kill the text with @kbd{C-w}. For example if you want to kill a
121 paragraph, position the cursor to the beginning of the paragraph and
122 type @kbd{C-SPC}. Then go to the end of the paragraph and type
123 @kbd{C-w}. The entire paragraph will be deleted. You can also select the
124 text with a mouse and type @kbd{C-w} to kill the entire
125 region. @xref{Killing,,,xemacs,XEmacs User's Manual}, for more information.
128 Save the text in a buffer or a file (@pxref{Accumulating
129 Text,,,xemacs,XEmacs User's Manual}).
131 You can convert the case of the text with @kbd{C-x C-l} or @kbd{C-x C-u}
132 If you type @kbd{C-x C-u} the selected text will become all
133 upper-case. If you type @kbd{C-x C-l} the selected text will become all
136 Print hardcopy with @kbd{M-x
137 print-region}. @xref{Hardcopy,,,xemacs,XEmacs User's Manual}, for more
138 information. This command will print a hardcopy of only the selected
141 Indent it with @kbd{C-x @key{TAB}} or @kbd{C-M-\}
142 @xref{Indentation,,,xemacs,XEmacs User's Manual}, for more information.
146 @comment node-name, next, previous, up
147 @node Moving Text, Accumulating text, Region Operation, Select and Move
156 The most common way to move or copy text in Emacs is through
157 @dfn{killing} or @samp{cutting} it and then @dfn{yanking} or
158 @samp{pasting} it. You can also use the @b{Cut} or @b{Copy} option from
159 the @b{Edit} menu for killing and copying respectively. @xref{Edit menu}
160 for reviewing the commands for killing text. All the killed text
161 in Emacs is recorded in the @dfn{kill ring}. Since there is only one
162 kill ring in Emacs, you can kill text in one buffer and yank it in
163 another buffer. To @samp{paste} or
164 @samp{yank} the killed text you can use the following commands:
167 This command will yank or paste the last killed text (@code{yank}).
169 Save region as last killed text without actually killing it
170 (@code{copy-region-as-kill}). You can use this command to copy a
171 selected region and then yank (or paste) it without actually removing it
174 Append next kill to last batch of killed text
175 (@code{append-next-kill}). This command will append whatever you killed
176 last to what you kill now. Then later you will be able to yank the
177 entire appended text from the @dfn{kill ring}.
180 @comment node-name, next, previous, up
181 @node Accumulating text, , Moving Text, Select and Move
182 @section Accumulating Text
183 @findex append-to-buffer
184 @findex prepend-to-buffer
185 @findex copy-to-buffer
186 @findex append-to-file
188 @cindex accumulating text
189 @cindex rectangle commands
191 @cindex temporary storage
193 The following commands can be used for accumulating text from
194 different buffers into one place or for copying one region of text into
198 @item M-x append-to-buffer
199 Append region to contents of specified buffer
200 (@code{append-to-buffer}). After you type in this command and press
201 @key{RET}, Emacs will prompt you for a buffer name. You will see a
202 message in the echo area:
204 Append to buffer: (default <buffer name>)
207 After you type in a buffer name, a copy of the region will be inserted
208 at the location of the cursor into that buffer. If there is no buffer
209 with the name given by you, Emacs will create a new buffer with that
210 name. By default the cursor's position in the <buffer name> is at the end.
211 @item M-x prepend-to-buffer
212 Prepend region to contents of specified buffer. This command is similar
213 to the above command except that the cursor in the buffer (by default)
214 is at the beginning rather than at the end.
215 @item M-x copy-to-buffer
216 Copy region into specified buffer, deleting that buffer's old
217 contents. This command will also prompt you for a buffer name.
218 @item M-x insert-buffer
219 Insert contents of specified buffer into current buffer at point. This
220 command will prompt you for a buffername which you want to be copied
221 into the current buffer at the location of the cursor.
222 @item M-x append-to-file
223 This command will prompt you for a filename and append the region to
224 the end of the contents of the specified file.
228 @xref{Accumulating Text,,,xemacs,XEmacs User's Manual}, for more
229 information regarding this topic.
231 You can also use @dfn{rectangle commands} for operating on rectangular
232 areas of text. @xref{Rectangles,,,xemacs,XEmacs User's Manual}, for more
233 information regarding rectangle commands.
235 Emacs also provides @dfn{registers} which serve as temporary storage for
236 text or positions. Each register has a one character name and they can
237 store @dfn{regions}, a @dfn{rectangle}, or a @dfn{mark} i.e. a cursor
238 position. Whatever you store in register stays there until you store
239 something else in that register. To find out about commands which
240 manipulate registers @xref{Registers,,,xemacs,XEmacs User's Manual}.