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