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