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