]> code.delx.au - gnu-emacs/blob - doc/emacs/killing.texi
Add 2009 to copyright years.
[gnu-emacs] / doc / emacs / killing.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
3 @c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5
6 @node Killing, Yanking, Mark, Top
7 @chapter Killing and Moving Text
8
9 @ifnottex
10 @raisesections
11 @end ifnottex
12
13 @dfn{Killing} means erasing text and copying it into the @dfn{kill
14 ring}, from which you can bring it back into the buffer by
15 @dfn{yanking} it. (Some applications use the terms ``cutting'' and
16 ``pasting'' for similar operations.) This is the most common way of
17 moving or copying text within Emacs. It is very versatile, because
18 there are commands for killing many different types of syntactic
19 units.
20
21 @iftex
22 @section Deletion and Killing
23 @end iftex
24
25 @cindex killing text
26 @cindex cutting text
27 @cindex deletion
28 Most commands which erase text from the buffer save it in the kill
29 ring. These are known as @dfn{kill} commands. The kill ring stores
30 several recent kills, not just the last one, so killing is a very safe
31 operation: when you make a new kill, you don't have to worry much
32 about losing text that you previously killed.
33
34 You can yank text from the kill ring into any position in a buffer,
35 including a position in a different buffer; the kill ring is shared by
36 all buffers. The @kbd{C-/} (@code{undo}) command can undo both kill
37 and delete commands (@pxref{Undo}); the importance of the kill ring is
38 that you can yank the text in a different place.
39
40 Commands that erase text but do not save it in the kill ring are
41 known as @dfn{delete} commands. These include @kbd{C-d}
42 (@code{delete-char}) and @key{DEL} (@code{delete-backward-char}),
43 which delete only one character at a time, and those commands that
44 delete only spaces or newlines. Commands that can erase significant
45 amounts of nontrivial data generally do a kill operation instead. The
46 commands' names and individual descriptions use the words @samp{kill}
47 and @samp{delete} to say which kind of operation they perform.
48
49 @vindex kill-read-only-ok
50 @cindex read-only text, killing
51 Some specialized buffers contain @dfn{read-only text}, which cannot
52 be modified and therefore cannot be killed. But some users like to
53 use the kill commands to copy read-only text into the kill ring,
54 without actually changing it. Therefore, the kill commands work
55 specially in a read-only buffer: they move over text, and copy it to
56 the kill ring, without actually deleting it from the buffer.
57 Normally, kill commands beep and display an error message when this
58 happens. But if you set the variable @code{kill-read-only-ok} to a
59 non-@code{nil} value, they just print a message in the echo area to
60 explain why the text has not been erased.
61
62 You can also use the mouse to kill and yank. @xref{Cut and Paste}.
63
64 @menu
65 * Deletion:: Commands for deleting small amounts of text and
66 blank areas.
67 * Killing by Lines:: How to kill entire lines of text at one time.
68 * Other Kill Commands:: Commands to kill large regions of text and
69 syntactic units such as words and sentences.
70 @end menu
71
72 @need 1500
73 @node Deletion
74 @subsection Deletion
75 @findex delete-backward-char
76 @findex delete-char
77
78 Deletion means erasing text and not saving it in the kill ring. For
79 the most part, the Emacs commands that delete text are those that
80 erase just one character or only whitespace.
81
82 @table @kbd
83 @item C-d
84 @itemx @key{Delete}
85 Delete next character (@code{delete-char}).
86 @item @key{DEL}
87 @itemx @key{Backspace}
88 Delete previous character (@code{delete-backward-char}).
89 @item M-\
90 Delete spaces and tabs around point (@code{delete-horizontal-space}).
91 @item M-@key{SPC}
92 Delete spaces and tabs around point, leaving one space
93 (@code{just-one-space}).
94 @item C-x C-o
95 Delete blank lines around the current line (@code{delete-blank-lines}).
96 @item M-^
97 Join two lines by deleting the intervening newline, along with any
98 indentation following it (@code{delete-indentation}).
99 @end table
100
101 We have already described the basic deletion commands @kbd{C-d}
102 (@code{delete-char}) and @key{DEL} (@code{delete-backward-char}).
103 @xref{Erasing}.
104
105 @kindex M-\
106 @findex delete-horizontal-space
107 @kindex M-SPC
108 @findex just-one-space
109 The other delete commands are those that delete only whitespace
110 characters: spaces, tabs and newlines. @kbd{M-\}
111 (@code{delete-horizontal-space}) deletes all the spaces and tab
112 characters before and after point. With a prefix argument, this only
113 deletes spaces and tab characters before point. @kbd{M-@key{SPC}}
114 (@code{just-one-space}) does likewise but leaves a single space after
115 point, regardless of the number of spaces that existed previously
116 (even if there were none before). With a numeric argument @var{n}, it
117 leaves @var{n} spaces after point.
118
119 @kbd{C-x C-o} (@code{delete-blank-lines}) deletes all blank lines
120 after the current line. If the current line is blank, it deletes all
121 blank lines preceding the current line as well (leaving one blank line,
122 the current line). On a solitary blank line, it deletes that line.
123
124 @kbd{M-^} (@code{delete-indentation}) joins the current line and the
125 previous line, by deleting a newline and all surrounding spaces, usually
126 leaving a single space. @xref{Indentation,M-^}.
127
128 @node Killing by Lines
129 @subsection Killing by Lines
130
131 @table @kbd
132 @item C-k
133 Kill rest of line or one or more lines (@code{kill-line}).
134 @item C-S-backspace
135 Kill an entire line at once (@code{kill-whole-line})
136 @end table
137
138 @kindex C-k
139 @findex kill-line
140 The simplest kill command is @kbd{C-k}. If given at the beginning
141 of a line, it kills all the text on the line@footnote{Here, ``line''
142 means a logical text line, not a screen line. @xref{Continuation
143 Lines}.}, leaving it blank. When used on a blank line, it kills the
144 whole line including its newline.
145
146 More precisely, @kbd{C-k} kills from point up to the end of the
147 line, unless it is at the end of a line. In that case it kills the
148 newline following point, thus merging the next line into the current
149 one. Spaces and tabs at the end of the line are ignored when deciding
150 which case applies, so as long as point is after the last visible
151 character in the line, you can be sure that @kbd{C-k} will kill the
152 newline. To kill an entire non-blank line, go to the beginning and
153 type @kbd{C-k} twice.
154
155 When @kbd{C-k} is given a positive argument @var{n}, it kills
156 @var{n} lines and the newlines that follow them (text on the current
157 line before point is not killed). With a negative argument
158 @minus{}@var{n}, it kills @var{n} lines preceding the current line,
159 together with the text on the current line before point. @kbd{C-k}
160 with an argument of zero kills the text before point on the current
161 line.
162
163 @vindex kill-whole-line
164 If the variable @code{kill-whole-line} is non-@code{nil}, @kbd{C-k} at
165 the very beginning of a line kills the entire line including the
166 following newline. This variable is normally @code{nil}.
167
168 @kindex C-S-backspace
169 @findex kill-whole-line
170 @kbd{C-S-backspace} (@code{kill-whole-line}) will kill a whole line
171 including its newline regardless of the position of point within the
172 line. Note that many character terminals will prevent you from typing
173 the key sequence @kbd{C-S-backspace}.
174
175 @node Other Kill Commands
176 @subsection Other Kill Commands
177 @findex kill-region
178 @kindex C-w
179
180 @table @kbd
181 @item C-w
182 Kill region (@code{kill-region}). @xref{Mark}.
183 @item M-w
184 Save region as last killed text without actually killing it
185 (@code{kill-ring-save}). Some programs call this ``copying.''
186 @item M-d
187 Kill word (@code{kill-word}). @xref{Words}.
188 @item M-@key{DEL}
189 Kill word backwards (@code{backward-kill-word}).
190 @item C-x @key{DEL}
191 Kill back to beginning of sentence (@code{backward-kill-sentence}).
192 @xref{Sentences}.
193 @item M-k
194 Kill to end of sentence (@code{kill-sentence}).
195 @item C-M-k
196 Kill the following balanced expression (@code{kill-sexp}). @xref{Expressions}.
197 @item M-z @var{char}
198 Kill through the next occurrence of @var{char} (@code{zap-to-char}).
199 @end table
200
201 Apart from @kbd{C-k}, the most commonly-used kill command is
202 @kbd{C-w} (@code{kill-region}), which kills the text in the region
203 (i.e., between point and mark). @xref{Mark}. If the mark is inactive
204 when you type @kbd{C-w}, it first reactivates the mark where it was
205 last set. The mark is deactivated at the end of the command.
206
207 @kindex M-w
208 @findex kill-ring-save
209 The command @kbd{M-w} (@code{kill-ring-save}) copies the region into
210 the kill ring without removing it from the buffer. This is
211 approximately equivalent to @kbd{C-w} followed by @kbd{C-/}, except
212 that @kbd{M-w} does not alter the undo history.
213
214 Emacs also provides commands to kill specific syntactic units:
215 words, with @kbd{M-@key{DEL}} and @kbd{M-d} (@pxref{Words}); balanced
216 expressions, with @kbd{C-M-k} (@pxref{Expressions}); and sentences,
217 with @kbd{C-x @key{DEL}} and @kbd{M-k} (@pxref{Sentences}).
218
219 @kindex M-z
220 @findex zap-to-char
221 The command @kbd{M-z} (@code{zap-to-char}) combines killing with
222 searching: it reads a character and kills from point up to (and
223 including) the next occurrence of that character in the buffer. A
224 numeric argument acts as a repeat count; a negative argument means to
225 search backward and kill text before point.
226
227 @node Yanking, Accumulating Text, Killing, Top
228 @section Yanking
229 @cindex moving text
230 @cindex copying text
231 @cindex kill ring
232 @cindex yanking
233 @cindex pasting
234
235 @dfn{Yanking} means reinserting text previously killed. The usual
236 way to move or copy text is to kill it and then yank it elsewhere one
237 or more times.
238
239 @table @kbd
240 @item C-y
241 Yank last killed text (@code{yank}).
242 @item M-y
243 Replace text just yanked with an earlier batch of killed text
244 (@code{yank-pop}).
245 @item C-M-w
246 Append next kill to last batch of killed text (@code{append-next-kill}).
247 @end table
248
249 On graphical displays with window systems, if there is a current
250 selection in some other application, and you selected it more recently
251 than you killed any text in Emacs, @kbd{C-y} copies the selection
252 instead of text killed within Emacs.
253
254 @menu
255 * Kill Ring:: Where killed text is stored. Basic yanking.
256 * Appending Kills:: Several kills in a row all yank together.
257 * Earlier Kills:: Yanking something killed some time ago.
258 @end menu
259
260 @node Kill Ring
261 @subsection The Kill Ring
262
263 All killed text is recorded in the @dfn{kill ring}, a list of blocks
264 of text that have been killed. There is only one kill ring, shared by
265 all buffers, so you can kill text in one buffer and yank it in another
266 buffer. This is the usual way to move text from one file to another.
267 (There are several other methods: for instance, you could store the
268 text in a register. @xref{Registers}, for information about
269 registers. @xref{Accumulating Text}, for some other ways to move text
270 around.)
271
272 @kindex C-y
273 @findex yank
274 The command @kbd{C-y} (@code{yank}) reinserts the text of the most
275 recent kill, leaving the cursor at the end of the text. It also adds
276 the position of the beginning of the text to the mark ring, without
277 activating the mark; this allows you to jump easily to that position
278 with @kbd{C-x C-x} (@pxref{Setting Mark}). With a plain prefix
279 argument (@kbd{C-u C-y}), it instead leaves the cursor in front of the
280 text, and adds the position of the end of the text to the mark ring.
281 Using other sort of prefix argument specifies an earlier kill; for
282 example, @kbd{C-u 4 C-y} reinserts the fourth most recent kill.
283 @xref{Earlier Kills}.
284
285 @cindex yanking and text properties
286 @vindex yank-excluded-properties
287 The yank commands discard certain properties from the yanked text.
288 These are properties that might lead to annoying results, such as
289 causing the text to respond to the mouse or specifying key bindings.
290 The list of properties to discard is stored in the variable
291 @code{yank-excluded-properties}. Yanking of register contents and
292 rectangles also discard these properties. @xref{Text Properties,,,
293 elisp, the Emacs Lisp Reference Manual}, for more information about
294 text properties.
295
296 @node Appending Kills
297 @subsection Appending Kills
298
299 @cindex appending kills in the ring
300 Normally, each kill command pushes a new entry onto the kill ring.
301 However, two or more kill commands in a row combine their text into a
302 single entry, so that a single @kbd{C-y} yanks all the text as a unit,
303 just as it was before it was killed.
304
305 Thus, if you want to yank text as a unit, you need not kill all of it
306 with one command; you can keep killing line after line, or word after
307 word, until you have killed it all, and you can still get it all back at
308 once.
309
310 Commands that kill forward from point add onto the end of the previous
311 killed text. Commands that kill backward from point add text onto the
312 beginning. This way, any sequence of mixed forward and backward kill
313 commands puts all the killed text into one entry without rearrangement.
314 Numeric arguments do not break the sequence of appending kills. For
315 example, suppose the buffer contains this text:
316
317 @example
318 This is a line @point{}of sample text.
319 @end example
320
321 @noindent
322 with point shown by @point{}. If you type @kbd{M-d M-@key{DEL} M-d
323 M-@key{DEL}}, killing alternately forward and backward, you end up with
324 @samp{a line of sample} as one entry in the kill ring, and @samp{This
325 is@ @ text.} in the buffer. (Note the double space between @samp{is}
326 and @samp{text}, which you can clean up with @kbd{M-@key{SPC}} or
327 @kbd{M-q}.)
328
329 Another way to kill the same text is to move back two words with
330 @kbd{M-b M-b}, then kill all four words forward with @kbd{C-u M-d}.
331 This produces exactly the same results in the buffer and in the kill
332 ring. @kbd{M-f M-f C-u M-@key{DEL}} kills the same text, all going
333 backward; once again, the result is the same. The text in the kill ring
334 entry always has the same order that it had in the buffer before you
335 killed it.
336
337 @kindex C-M-w
338 @findex append-next-kill
339 If a kill command is separated from the last kill command by other
340 commands (not just numeric arguments), it starts a new entry on the kill
341 ring. But you can force it to append by first typing the command
342 @kbd{C-M-w} (@code{append-next-kill}) right before it. The @kbd{C-M-w}
343 tells the following command, if it is a kill command, to append the text
344 it kills to the last killed text, instead of starting a new entry. With
345 @kbd{C-M-w}, you can kill several separated pieces of text and
346 accumulate them to be yanked back in one place.@refill
347
348 A kill command following @kbd{M-w} (@code{kill-ring-save}) does not
349 append to the text that @kbd{M-w} copied into the kill ring.
350
351 @node Earlier Kills
352 @subsection Yanking Earlier Kills
353
354 @cindex yanking previous kills
355 @kindex M-y
356 @findex yank-pop
357 To recover killed text that is no longer the most recent kill, use the
358 @kbd{M-y} command (@code{yank-pop}). It takes the text previously
359 yanked and replaces it with the text from an earlier kill. So, to
360 recover the text of the next-to-the-last kill, first use @kbd{C-y} to
361 yank the last kill, and then use @kbd{M-y} to replace it with the
362 previous kill. @kbd{M-y} is allowed only after a @kbd{C-y} or another
363 @kbd{M-y}.
364
365 You can understand @kbd{M-y} in terms of a ``last yank'' pointer which
366 points at an entry in the kill ring. Each time you kill, the ``last
367 yank'' pointer moves to the newly made entry at the front of the ring.
368 @kbd{C-y} yanks the entry which the ``last yank'' pointer points to.
369 @kbd{M-y} moves the ``last yank'' pointer to a different entry, and the
370 text in the buffer changes to match. Enough @kbd{M-y} commands can move
371 the pointer to any entry in the ring, so you can get any entry into the
372 buffer. Eventually the pointer reaches the end of the ring; the next
373 @kbd{M-y} loops back around to the first entry again.
374
375 @kbd{M-y} moves the ``last yank'' pointer around the ring, but it does
376 not change the order of the entries in the ring, which always runs from
377 the most recent kill at the front to the oldest one still remembered.
378
379 @kbd{M-y} can take a numeric argument, which tells it how many entries
380 to advance the ``last yank'' pointer by. A negative argument moves the
381 pointer toward the front of the ring; from the front of the ring, it
382 moves ``around'' to the last entry and continues forward from there.
383
384 Once the text you are looking for is brought into the buffer, you can
385 stop doing @kbd{M-y} commands and it will stay there. It's just a copy
386 of the kill ring entry, so editing it in the buffer does not change
387 what's in the ring. As long as no new killing is done, the ``last
388 yank'' pointer remains at the same place in the kill ring, so repeating
389 @kbd{C-y} will yank another copy of the same previous kill.
390
391 If you know how many @kbd{M-y} commands it would take to find the
392 text you want, you can yank that text in one step using @kbd{C-y} with
393 a numeric argument. @kbd{C-y} with an argument restores the text from
394 the specified kill ring entry, counting back from the most recent as
395 1. Thus, @kbd{C-u 2 C-y} gets the next-to-the-last block of killed
396 text---it is equivalent to @kbd{C-y M-y}. @kbd{C-y} with a numeric
397 argument starts counting from the ``last yank'' pointer, and sets the
398 ``last yank'' pointer to the entry that it yanks.
399
400 @vindex kill-ring-max
401 The length of the kill ring is controlled by the variable
402 @code{kill-ring-max}; no more than that many blocks of killed text are
403 saved.
404
405 @vindex kill-ring
406 The actual contents of the kill ring are stored in a variable named
407 @code{kill-ring}; you can view the entire contents of the kill ring with
408 the command @kbd{C-h v kill-ring}.
409
410 @node Accumulating Text, Rectangles, Yanking, Top
411 @section Accumulating Text
412 @findex append-to-buffer
413 @findex prepend-to-buffer
414 @findex copy-to-buffer
415 @findex append-to-file
416
417 @cindex accumulating scattered text
418 Usually we copy or move text by killing it and yanking it, but there
419 are other convenient methods for copying one block of text in many
420 places, or for copying many scattered blocks of text into one place.
421 Here we describe the commands to accumulate scattered pieces of text
422 into a buffer or into a file.
423
424 @table @kbd
425 @item M-x append-to-buffer
426 Append region to the contents of a specified buffer.
427 @item M-x prepend-to-buffer
428 Prepend region to the contents of a specified buffer.
429 @item M-x copy-to-buffer
430 Copy region into a specified buffer, deleting that buffer's old contents.
431 @item M-x insert-buffer
432 Insert the contents of a specified buffer into current buffer at point.
433 @item M-x append-to-file
434 Append region to the contents of a specified file, at the end.
435 @end table
436
437 To accumulate text into a buffer, use @kbd{M-x append-to-buffer}.
438 This reads a buffer name, then inserts a copy of the region into the
439 buffer specified. If you specify a nonexistent buffer,
440 @code{append-to-buffer} creates the buffer. The text is inserted
441 wherever point is in that buffer. If you have been using the buffer for
442 editing, the copied text goes into the middle of the text of the buffer,
443 starting from wherever point happens to be at that moment.
444
445 Point in that buffer is left at the end of the copied text, so
446 successive uses of @code{append-to-buffer} accumulate the text in the
447 specified buffer in the same order as they were copied. Strictly
448 speaking, @code{append-to-buffer} does not always append to the text
449 already in the buffer---it appends only if point in that buffer is at the end.
450 However, if @code{append-to-buffer} is the only command you use to alter
451 a buffer, then point is always at the end.
452
453 @kbd{M-x prepend-to-buffer} is just like @code{append-to-buffer}
454 except that point in the other buffer is left before the copied text, so
455 successive prependings add text in reverse order. @kbd{M-x
456 copy-to-buffer} is similar, except that any existing text in the other
457 buffer is deleted, so the buffer is left containing just the text newly
458 copied into it.
459
460 The command @kbd{M-x insert-buffer} can be used to retrieve the
461 accumulated text from another buffer. This prompts for the name of a
462 buffer, and inserts a copy of all the text in that buffer into the
463 current buffer at point, leaving point at the beginning of the
464 inserted text. It also adds the position of the end of the inserted
465 text to the mark ring, without activating the mark. @xref{Buffers},
466 for background information on buffers.
467
468 Instead of accumulating text in a buffer, you can append text
469 directly into a file with @kbd{M-x append-to-file}. This prompts for
470 a filename, and adds the text of the region to the end of the
471 specified file. The file is changed immediately on disk.
472
473 You should use @code{append-to-file} only with files that are
474 @emph{not} being visited in Emacs. Using it on a file that you are
475 editing in Emacs would change the file behind Emacs's back, which
476 can lead to losing some of your editing.
477
478 Another way to move text around is to store it in a register.
479 @xref{Registers}.
480
481 @node Rectangles, CUA Bindings, Accumulating Text, Top
482 @section Rectangles
483 @cindex rectangle
484 @cindex columns (and rectangles)
485 @cindex killing rectangular areas of text
486
487 @dfn{Rectangle} commands operate on rectangular areas of the text:
488 all the characters between a certain pair of columns, in a certain
489 range of lines. Emacs has commands to kill rectangles, yank killed
490 rectangles, clear them out, fill them with blanks or text, or delete
491 them. Rectangle commands are useful with text in multicolumn formats,
492 and for changing text into or out of such formats.
493
494 @cindex mark rectangle
495 When you must specify a rectangle for a command to work on, you do it
496 by putting the mark at one corner and point at the opposite corner. The
497 rectangle thus specified is called the @dfn{region-rectangle} because
498 you control it in much the same way as the region is controlled. But
499 remember that a given combination of point and mark values can be
500 interpreted either as a region or as a rectangle, depending on the
501 command that uses them.
502
503 If point and the mark are in the same column, the rectangle they
504 delimit is empty. If they are in the same line, the rectangle is one
505 line high. This asymmetry between lines and columns comes about
506 because point (and likewise the mark) is between two columns, but within
507 a line.
508
509 @table @kbd
510 @item C-x r k
511 Kill the text of the region-rectangle, saving its contents as the
512 ``last killed rectangle'' (@code{kill-rectangle}).
513 @item C-x r d
514 Delete the text of the region-rectangle (@code{delete-rectangle}).
515 @item C-x r y
516 Yank the last killed rectangle with its upper left corner at point
517 (@code{yank-rectangle}).
518 @item C-x r o
519 Insert blank space to fill the space of the region-rectangle
520 (@code{open-rectangle}). This pushes the previous contents of the
521 region-rectangle rightward.
522 @item C-x r c
523 Clear the region-rectangle by replacing all of its contents with spaces
524 (@code{clear-rectangle}).
525 @item M-x delete-whitespace-rectangle
526 Delete whitespace in each of the lines on the specified rectangle,
527 starting from the left edge column of the rectangle.
528 @item C-x r t @var{string} @key{RET}
529 Replace rectangle contents with @var{string} on each line
530 (@code{string-rectangle}).
531 @item M-x string-insert-rectangle @key{RET} @var{string} @key{RET}
532 Insert @var{string} on each line of the rectangle.
533 @end table
534
535 The rectangle operations fall into two classes: commands for
536 deleting and inserting rectangles, and commands for blank rectangles.
537
538 @kindex C-x r k
539 @kindex C-x r d
540 @findex kill-rectangle
541 @findex delete-rectangle
542 There are two ways to get rid of the text in a rectangle: you can
543 discard the text (delete it) or save it as the ``last killed''
544 rectangle. The commands for these two ways are @kbd{C-x r d}
545 (@code{delete-rectangle}) and @kbd{C-x r k} (@code{kill-rectangle}). In
546 either case, the portion of each line that falls inside the rectangle's
547 boundaries is deleted, causing any following text on the line to
548 move left into the gap.
549
550 Note that ``killing'' a rectangle is not killing in the usual sense; the
551 rectangle is not stored in the kill ring, but in a special place that
552 can only record the most recent rectangle killed. This is because yanking
553 a rectangle is so different from yanking linear text that different yank
554 commands have to be used. It is hard to define yank-popping for rectangles,
555 so we do not try.
556
557 @kindex C-x r y
558 @findex yank-rectangle
559 To yank the last killed rectangle, type @kbd{C-x r y}
560 (@code{yank-rectangle}). Yanking a rectangle is the opposite of killing
561 one. Point specifies where to put the rectangle's upper left corner.
562 The rectangle's first line is inserted there, the rectangle's second
563 line is inserted at the same horizontal position, but one line
564 vertically down, and so on. The number of lines affected is determined
565 by the height of the saved rectangle.
566
567 You can convert single-column lists into double-column lists using
568 rectangle killing and yanking; kill the second half of the list as a
569 rectangle and then yank it beside the first line of the list.
570 @xref{Two-Column}, for another way to edit multi-column text.
571
572 You can also copy rectangles into and out of registers with @kbd{C-x r
573 r @var{r}} and @kbd{C-x r i @var{r}}. @xref{RegRect,,Rectangle
574 Registers}.
575
576 @kindex C-x r o
577 @findex open-rectangle
578 @kindex C-x r c
579 @findex clear-rectangle
580 There are two commands you can use for making blank rectangles:
581 @kbd{C-x r c} (@code{clear-rectangle}) which blanks out existing text,
582 and @kbd{C-x r o} (@code{open-rectangle}) which inserts a blank
583 rectangle. Clearing a rectangle is equivalent to deleting it and then
584 inserting a blank rectangle of the same size.
585
586 @findex delete-whitespace-rectangle
587 The command @kbd{M-x delete-whitespace-rectangle} deletes horizontal
588 whitespace starting from a particular column. This applies to each of
589 the lines in the rectangle, and the column is specified by the left
590 edge of the rectangle. The right edge of the rectangle does not make
591 any difference to this command.
592
593 @kindex C-x r t
594 @findex string-rectangle
595 The command @kbd{C-x r t} (@code{string-rectangle}) replaces the
596 contents of a region-rectangle with a string on each line. The
597 string's width need not be the same as the width of the rectangle. If
598 the string's width is less, the text after the rectangle shifts left;
599 if the string is wider than the rectangle, the text after the
600 rectangle shifts right.
601
602 @findex string-insert-rectangle
603 The command @kbd{M-x string-insert-rectangle} is similar to
604 @code{string-rectangle}, but inserts the string on each line,
605 shifting the original text to the right.
606
607 @node CUA Bindings, Registers, Rectangles, Top
608 @section CUA Bindings
609 @findex cua-mode
610 @vindex cua-mode
611 @cindex CUA key bindings
612 @vindex cua-enable-cua-keys
613 The command @kbd{M-x cua-mode} sets up key bindings that are
614 compatible with the Common User Access (CUA) system used in many other
615 applications. @kbd{C-x} means cut (kill), @kbd{C-c} copy, @kbd{C-v}
616 paste (yank), and @kbd{C-z} undo. Standard Emacs commands like
617 @kbd{C-x C-c} still work, because @kbd{C-x} and @kbd{C-c} only take
618 effect when the mark is active (and the region is highlighted).
619 However, if you don't want to override these bindings in Emacs at all,
620 set @code{cua-enable-cua-keys} to @code{nil}.
621
622 To enter an Emacs command like @kbd{C-x C-f} while the mark is
623 active, use one of the following methods: either hold @kbd{Shift}
624 together with the prefix key, e.g. @kbd{S-C-x C-f}, or quickly type
625 the prefix key twice, e.g. @kbd{C-x C-x C-f}.
626
627 In CUA mode, typed text replaces the active region as in
628 Delete-Selection mode (@pxref{Mouse Commands}).
629
630 @cindex rectangle highlighting
631 CUA mode provides enhanced rectangle support with visible
632 rectangle highlighting. Use @kbd{C-RET} to start a rectangle,
633 extend it using the movement commands, and cut or copy it using
634 @kbd{C-x} or @kbd{C-c}. @kbd{RET} moves the cursor to the next
635 (clockwise) corner of the rectangle, so you can easily expand it in
636 any direction. Normal text you type is inserted to the left or right
637 of each line in the rectangle (on the same side as the cursor).
638
639 With CUA you can easily copy text and rectangles into and out of
640 registers by providing a one-digit numeric prefix to the kill, copy,
641 and yank commands, e.g. @kbd{C-1 C-c} copies the region into register
642 @code{1}, and @kbd{C-2 C-v} yanks the contents of register @code{2}.
643
644 @cindex global mark
645 CUA mode also has a global mark feature which allows easy moving and
646 copying of text between buffers. Use @kbd{C-S-SPC} to toggle the
647 global mark on and off. When the global mark is on, all text that you
648 kill or copy is automatically inserted at the global mark, and text
649 you type is inserted at the global mark rather than at the current
650 position.
651
652 For example, to copy words from various buffers into a word list in
653 a given buffer, set the global mark in the target buffer, then
654 navigate to each of the words you want in the list, mark it (e.g. with
655 @kbd{S-M-f}), copy it to the list with @kbd{C-c} or @kbd{M-w}, and
656 insert a newline after the word in the target list by pressing
657 @key{RET}.
658
659 @ifnottex
660 @lowersections
661 @end ifnottex
662
663 @ignore
664 arch-tag: d8da8f96-0928-449a-816e-ff2d3497866c
665 @end ignore