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