|
|
1.1 root 1: Info file emacs, produced by texinfo-format-buffer -*-Text-*-
2: from file emacs.tex
3:
4: This file documents the GNU Emacs editor.
5:
6: Copyright (C) 1985, 1986 Richard M. Stallman.
7:
8: Permission is granted to make and distribute verbatim copies of
9: this manual provided the copyright notice and this permission notice
10: are preserved on all copies.
11:
12: Permission is granted to copy and distribute modified versions of this
13: manual under the conditions for verbatim copying, provided also that the
14: sections entitled "The GNU Manifesto", "Distribution" and "GNU Emacs
15: General Public License" are included exactly as in the original, and
16: provided that the entire resulting derived work is distributed under the
17: terms of a permission notice identical to this one.
18:
19: Permission is granted to copy and distribute translations of this manual
20: into another language, under the above conditions for modified versions,
21: except that the sections entitled "The GNU Manifesto", "Distribution"
22: and "GNU Emacs General Public License" may be included in a translation
23: approved by the author instead of in the original English.
24:
25:
26: File: emacs Node: Using Region, Prev: Setting Mark, Up: Mark, Next: Marking Objects
27:
28: Operating on the Region
29: =======================
30:
31: Once you have created an active region, you can do many things to
32: the text in it:
33: * Kill it with `C-w' (*Note Killing::).
34: * Save it in a register with `C-x x' (*Note Registers::).
35: * Save it in a buffer or a file (*Note Accumulating Text::).
36: * Convert case with `C-x C-l' or `C-x C-u' (*Note Case::).
37: * Evaluate it as Lisp code with `M-x eval-region' (*Note Lisp Eval::).
38: * Fill it as text with `M-g' (*Note Filling::).
39: * Print hardcopy with `M-x print-region' (*Note Hardcopy::).
40: * Indent it with `C-x TAB' or `C-M-\' (*Note Indentation::).
41:
42:
43: File: emacs Node: Marking Objects, Prev: Using Region, Up: Mark, Next: Mark Ring
44:
45: Commands to Mark Textual Objects
46: ================================
47:
48: There are commands for placing point and the mark around a textual
49: object such as a word, list, paragraph or page.
50:
51: `M-@'
52: Set mark after end of next word (`mark-word'). This command and
53: the following one do not move point.
54: `C-M-@'
55: Set mark after end of next Lisp expression (`mark-sexp').
56: `M-h'
57: Put region around current paragraph (`mark-paragraph').
58: `C-M-h'
59: Put region around current Lisp defun (`mark-defun').
60: `C-x h'
61: Put region around entire buffer (`mark-whole-buffer').
62: `C-x C-p'
63: Put region around current page (`mark-page').
64:
65: `M-@' (`mark-word') puts the mark at the end of the next word,
66: while `C-M-@' (`mark-sexp') puts it at the end of the next Lisp
67: expression. These characters allow you to save a little typing or
68: redisplay, sometimes.
69:
70: Other commands set both point and mark, to delimit an object in the
71: buffer. `M-h' (`mark-paragraph') moves point to the beginning of
72: the paragraph that surrounds or follows point, and puts the mark at the end
73: of that paragraph (*Note Paragraphs::). `M-h' does all that's
74: necessary if you wish to indent, case-convert, or kill a whole paragraph.
75: `C-M-h' (`mark-defun') similarly puts point before and the mark
76: after the current or following defun (*Note Defuns::). `C-x C-p'
77: (`mark-page') puts point before the current page (or the next or
78: previous, according to the argument), and mark at the end (*Note Pages::).
79: The mark goes after the terminating page delimiter (to include it), while
80: point goes after the preceding page delimiter (to exclude it). Finally,
81: `C-x h' (`mark-whole-buffer') sets up the entire buffer as the
82: region, by putting point at the beginning and the mark at the end.
83:
84:
85: File: emacs Node: Mark Ring, Prev: Marking Objects, Up: Mark
86:
87: The Mark Ring
88: =============
89:
90: Aside from delimiting the region, the mark is also useful for remembering
91: a spot that you may want to go back to. To make this feature more useful,
92: Emacs remembers 16 previous locations of the mark, in the "mark ring".
93: Most commands that set the mark push the old mark onto this ring. To
94: return to a marked location, use `C-u C-SPC' (or `C-u C-@'); this is
95: the command `set-mark-command' given a numeric argument. It moves
96: point to where the mark was, and restores the mark from the ring of former
97: marks. So repeated use of this command moves point to all of the old marks
98: on the ring, one by one. The marks you see go to the end of the ring,
99: so no marks are lost.
100:
101: Each buffer has its own mark ring. All editing commands use the current
102: buffer's mark ring. In particular, `C-u C-SPC' always stays in
103: the same buffer.
104:
105: Many commands that can move long distances, such as `M-<'
106: (`beginning-of-buffer'), start by setting the mark and saving the old
107: mark on the mark ring. This is to make it easier for you to move back
108: later. Searches do this except when they do not actually move point. You
109: can tell when a command sets the mark because `Mark Set' is printed in
110: the echo area.
111:
112: The variable `mark-ring-max' is the maximum number of entries to
113: keep in the mark ring. If that many entries exist and another one is
114: pushed, the last one in the list is discarded. Repeating `C-u
115: C-SPC' circulates through the limited number of entries that are
116: currently in the ring.
117:
118: The variable `mark-ring' holds the mark ring itself, as a list of
119: marker objects in the order most recent first. This variable is local
120: in every buffer.
121:
122:
123:
124: File: emacs Node: Killing, Prev: Mark, Up: Top, Next: Yanking
125:
126: Deletion and Killing
127: ====================
128:
129: Most commands which erase text from the buffer save it so that you can
130: get it back if you change your mind, or move or copy it to other parts of
131: the buffer. These commands are known as "kill" commands. The rest of
132: the commands that erase text do not save it; they are known as "delete"
133: commands. (This distinction is made only for erasure of text in the
134: buffer.)
135:
136: The delete commands include `C-d' (`delete-char') and DEL
137: (`delete-backward-char'), which delete only one character at a time, and
138: those commands that delete only spaces or newlines. Commands that can
139: destroy significant amounts of nontrivial data generally kill. The
140: commands' names and individual descriptions use the words `kill' and
141: `delete' to say which they do. If you do a kill or delete command by
142: mistake, you can use the `C-x u' (`undo') command to undo it (*Note
143: Undo::).
144:
145:
146: Deletion
147: --------
148:
149: `C-d'
150: Delete next character (`delete-char').
151: `DEL'
152: Delete previous character (`delete-backward-char').
153: `M-\'
154: Delete spaces and tabs around point (`delete-horizontal-space').
155: `M-SPC'
156: Delete spaces and tabs around point, leaving one space
157: (`just-one-space').
158: `C-x C-o'
159: Delete blank lines around the current line (`delete-blank-lines').
160: `M-^'
161: Join two lines by deleting the intervening newline, and any indentation
162: following it (`delete-indentation').
163:
164: The most basic delete commands are `C-d' (`delete-char') and
165: DEL (`delete-backward-char'). `C-d' deletes the character
166: after point, the one the cursor is "on top of". Point doesn't move.
167: DEL deletes the character before the cursor, and moves point back.
168: Newlines can be deleted like any other characters in the buffer; deleting a
169: newline joins two lines. Actually, `C-d' and DEL aren't always
170: delete commands; if given an argument, they kill instead, since they can
171: erase more than one character this way.
172:
173: The other delete commands are those which delete only formatting
174: characters: spaces, tabs and newlines. `M-\' (`delete-horizontal-space')
175: deletes all the spaces and tab characters before and after point.
176: `M-SPC' (`just-one-space') does likewise but leaves a single
177: space after point, regardless of the number of spaces that existed
178: previously (even zero).
179:
180: `C-x C-o' (`delete-blank-lines') deletes all blank lines after
181: the current line, and if the current line is blank deletes all blank lines
182: preceding the current line as well (leaving one blank line, the current
183: line). `M-^' (`delete-indentation') joins the current line and
184: the previous line, or the current line and the next line if given an
185: argument, by deleting a newline and all surrounding spaces, possibly
186: leaving a single space. *Note M-^: Indentation.
187:
188:
189: Killing by Lines
190: ----------------
191:
192: `C-k'
193: Kill rest of line or one or more lines (`kill-line').
194:
195: The simplest kill command is `C-k'. If given at the beginning of a
196: line, it kills all the text on the line, leaving it blank. If given on a
197: blank line, the blank line disappears. As a consequence, if you go to the
198: front of a non-blank line and type `C-k' twice, the line disappears
199: completely.
200:
201: More generally, `C-k' kills from point up to the end of the line,
202: unless it is at the end of a line. In that case it kills the newline
203: following the line, thus merging the next line into the current one.
204: Invisible spaces and tabs at the end of the line are ignored when deciding
205: which case applies, so if point appears to be at the end of the line, you
206: can be sure the newline will be killed.
207:
208: If `C-k' is given a positive argument, it kills that many lines and
209: the newlines that follow them (however, text on the current line before
210: point is spared). With a negative argument, it kills back to a number of
211: line beginnings. An argument of -2 means kill back to the second line
212: beginning. If point is at the beginning of a line, that line beginning
213: doesn't count, so `C-u - 2 C-k' with point at the front of a line kills
214: the two previous lines.
215:
216: `C-k' with an argument of zero kills all the text before point on the
217: current line.
218:
219:
220: Other Kill Commands
221: -------------------
222:
223: `C-w'
224: Kill region (from point to the mark) (`kill-region').
225: *Note Words::.
226: `M-d'
227: Kill word (`kill-word').
228: `M-DEL'
229: Kill word backwards (`backward-kill-word').
230: `C-x DEL'
231: Kill back to beginning of sentence (`backward-kill-sentence').
232: *Note Sentences::.
233: `M-k'
234: Kill to end of sentence (`kill-sentence').
235: `C-M-k'
236: Kill sexp (`kill-sexp'). *Note Lists::.
237: `M-z CHAR'
238: Kill up to next occurrence of CHAR (`zap-to-char').
239:
240: A kill command which is very general is `C-w' (`kill-region'),
241: which kills everything between point and the mark. With this command, you
242: can kill any contiguous sequence of characters, if you first set the mark
243: at one end of them and go to the other end.
244:
245: A convenient way of killing is combined with searching: `M-z'
246: (`zap-to-char') reads a character and kills from point up to (but not
247: including) the next occurrence of that character in the buffer. If there
248: is no next occurrence, killing goes to the end of the buffer. A numeric
249: argument acts as a repeat count. A negative argument means to search
250: backward and kill text before point.
251:
252: Other syntactic units can be killed: words, with `M-DEL' and `M-d' (*Note
253: Words::); sexps, with `C-M-k' (*Note Lists::); and sentences, with `C-x
254: DEL' and `M-k' (*Note Sentences::).
255:
256:
257: File: emacs Node: Yanking, Prev: Killing, Up: Top, Next: Accumulating Text
258:
259: Yanking
260: =======
261:
262: "Yanking" is getting back text which was killed. This is what some
263: systems call "pasting". The usual way to move or copy text is to kill it
264: and then yank it one or more times.
265:
266: `C-y'
267: Yank last killed text (`yank').
268: `M-y'
269: Replace re-inserted killed text with the previously killed text
270: (`yank-pop').
271: `M-w'
272: Save region as last killed text without actually killing it
273: (`copy-region-as-kill').
274: `C-M-w'
275: Append next kill to last batch of killed text (`append-next-kill').
276:
277: * Menu:
278:
279: * Kill Ring:: Where killed text is stored. Basic yanking.
280: * Appending Kills:: Several kills in a row all yank together.
281: * Earlier Kills:: Yanking something killed some time ago.
282:
283:
284: File: emacs Node: Kill Ring, Prev: Yanking, Up: Yanking, Next: Appending Kills
285:
286: The Kill Ring
287: -------------
288:
289: All killed text is recorded in the "kill ring", a list of blocks of
290: text that have been killed. There is only one kill ring, used in all
291: buffers, so you can kill text in one buffer and yank it in another buffer.
292: This is the usual way to move text from one file to another.
293: (*Note Accumulating Text::, for some other ways.)
294:
295: The command `C-y' (`yank') reinserts the text of the most recent
296: kill. It leaves the cursor at the end of the text. It sets the mark at
297: the beginning of the text. *Note Mark::.
298:
299: `C-u C-y' leaves the cursor in front of the text, and sets the mark
300: after it. This is only if the argument is specified with just a `C-u',
301: precisely. Any other sort of argument, including `C-u' and digits, has
302: an effect described below (under "Yanking Earlier Kills").
303:
304: If you wish to copy a block of text, you might want to use `M-w'
305: (`copy-region-as-kill'), which copies the region into the kill ring
306: without removing it from the buffer. This is approximately equivalent to
307: `C-w' followed by `C-y', except that `M-w' does not mark the
308: buffer as "modified" and does not temporarily change the screen.
309:
310:
311: File: emacs Node: Appending Kills, Prev: Kill Ring, Up: Yanking, Next: Earlier Kills
312:
313: Appending Kills
314: ---------------
315:
316: Normally, each kill command pushes a new block onto the kill ring.
317: However, two or more kill commands in a row combine their text into a
318: single entry, so that a single `C-y' gets it all back as it was before
319: it was killed. This means that you don't have to kill all the text in one
320: command; you can keep killing line after line, or word after word, until
321: you have killed it all, and you can still get it all back at once. (Thus
322: we join television in leading people to kill thoughtlessly.)
323:
324: Commands that kill forward from point add onto the end of the previous
325: killed text. Commands that kill backward from point add onto the
326: beginning. This way, any sequence of mixed forward and backward kill
327: commands puts all the killed text into one entry without rearrangement.
328: Numeric arguments do not break the sequence of appending kills. For
329: example, suppose the buffer contains
330:
331: This is the first
332: line of sample text
333: and here is the third.
334:
335: with point at the beginning of the second line. If you type `C-k C-u 2
336: M-DEL C-k', the first `C-k' kills the text `line of sample
337: text', `C-u 2 M-DEL' kills `the first' with the newline that
338: followed it, and the second `C-k' kills the newline after the second
339: line. The result is that the buffer contains `This is and here is the
340: third.' and a single kill entry contains `the firstRETline of
341: sample textRET'---all the killed text, in its original order.
342:
343: If a kill command is separated from the last kill command by other
344: commands (not just numeric arguments), it starts a new entry on the kill
345: ring. But you can force it to append by first typing the command `C-M-w'
346: (`append-next-kill') in front of it. The `C-M-w' tells the following
347: command, if it is a kill command, to append the text it kills to the last
348: killed text, instead of starting a new entry. With `C-M-w', you can kill
349: several separated pieces of text and accumulate them to be yanked back in
350: one place.
351:
352:
353: File: emacs Node: Earlier Kills, Prev: Appending Kills, Up: Yanking
354:
355: Yanking Earlier Kills
356: ---------------------
357:
358: To recover killed text that is no longer the most recent kill, you need
359: the `Meta-y' (`yank-pop') command. `M-y' can be used only after a `C-y' or
360: another `M-y'. It takes the text previously yanked and replaces it with
361: the text from an earlier kill. So, to recover the text of the
362: next-to-the-last kill, you first use `C-y' to recover the last kill, and
363: then use `M-y' to replace it with the previous kill.
364:
365: You can think in terms of a "last yank" pointer which points at an item
366: in the kill ring. Each time you kill, the "last yank" pointer moves to
367: the newly made item at the front of the ring. `C-y' yanks the item
368: which the "last yank" pointer points to. `M-y' moves the "last
369: yank" pointer to a different item, and the text in the buffer changes to
370: match. Enough `M-y' commands can move the pointer to any item in the
371: ring, so you can get any item into the buffer. Eventually the pointer
372: reaches the end of the ring; the next `M-y' moves it to the first item
373: again.
374:
375: Yanking moves the "last yank" pointer around the ring, but it does not
376: change the order of the entries in the ring, which always runs from the
377: most recent kill at the front to the oldest one still remembered.
378:
379: `M-y' can take a numeric argument, which tells it how many items to
380: advance the "last yank" pointer by. A negative argument moves the
381: pointer toward the front of the ring; from the front of the ring, it moves
382: to the last entry and starts moving forward from there.
383:
384: Once the text you are looking for is brought into the buffer, you can
385: stop doing `M-y' commands and it will stay there. It's just a copy of
386: the kill ring item, so editing it in the buffer does not change what's in
387: the ring. As long as no new killing is done, the "last yank" pointer
388: remains at the same place in the kill ring, so repeating `C-y' will
389: yank another copy of the same old kill.
390:
391: If you know how many `M-y' commands it would take to find the
392: text you want, you can yank that text in one step using `C-y' with
393: a numeric argument. `C-y' with an argument greater than one
394: restores the text the specified number of entries back in the kill
395: ring. Thus, `C-u 2 C-y' gets the next to the last block of killed
396: text. It is equivalent to `C-y M-y'. `C-y' with a numeric
397: argument starts counting from the "last yank" pointer, and sets the
398: "last yank" pointer to the entry that it yanks.
399:
400: The length of the kill ring is controlled by the variable
401: `kill-ring-max'; no more than that many blocks of killed text are
402: saved.
403:
404:
405: File: emacs Node: Accumulating Text, Prev: Yanking, Up: Top, Next: Rectangles
406:
407: Accumulating Text
408: =================
409:
410: Usually we copy or move text by killing it and yanking it, but there are
411: other ways that are useful for copying one block of text in many places, or
412: for copying many scattered blocks of text into one place.
413:
414: You can accumulate blocks of text from scattered locations either into a
415: buffer or into a file if you like. These commands are described here. You
416: can also use Emacs registers for storing and accumulating text.
417: *Note Registers::.
418:
419: `C-x a'
420: Append region to contents of specified buffer (`append-to-buffer').
421: `M-x prepend-to-buffer'
422: Prepend region to contents of specified buffer.
423: `M-x copy-to-buffer'
424: Copy region into specified buffer, deleting that buffer's old contents.
425: `M-x insert-buffer'
426: Insert contents of specified buffer into current buffer at point.
427: `M-x append-to-file'
428: Append region to contents of specified file, at the end.
429:
430: To accumulate text into a buffer, use the command `C-x a BUFFERNAME'
431: (`append-to-buffer'), which inserts a copy of the region into the
432: buffer BUFFERNAME, at the location of point in that buffer. If there
433: is no buffer with that name, one is created. If you append text into a
434: buffer which has been used for editing, the copied text goes into the
435: middle of the text of the buffer, wherever point happens to be in it.
436:
437: Point in that buffer is left at the end of the copied text, so successive
438: uses of `C-x a' accumulate the text in the specified buffer in the same
439: order as they were copied. Strictly speaking, `C-x a' does not always
440: append to the text already in the buffer; but if `C-x a' is the only
441: command used to alter a buffer, it does always append to the existing text
442: because point is always at the end.
443:
444: `M-x prepend-to-buffer' is just like `C-x a' except that point in
445: the other buffer is left before the copied text, so successive prependings
446: add text in reverse order. `M-x copy-to-buffer' is similar except that
447: any existing text in the other buffer is deleted, so the buffer is left
448: containing just the text newly copied into it.
449:
450: You can retrieve the accumulated text from that buffer with `M-x
451: insert-buffer'; this too takes BUFFERNAME as an argument. It inserts
452: a copy of the text in buffer BUFFERNAME into the selected buffer.
453: You could alternatively select the other buffer for editing, perhaps moving
454: text from it by killing or with `C-x a'. *Note Buffers::, for
455: background information on buffers.
456:
457: Instead of accumulating text within Emacs, in a buffer, you can append
458: text directly into a file with `M-x append-to-file', which takes
459: FILE-NAME as an argument. It adds the text of the region to the end
460: of the specified file. The file is changed immediately on disk. This
461: command is normally used with files that are not being visited in
462: Emacs. Using it on a file that Emacs is visiting can produce confusing
463: results, because the text inside Emacs for that file will not change
464: while the file itself changes.
465:
466:
467: File: emacs Node: Rectangles, Prev: Accumulating Text, Up: Top, Next: Registers
468:
469: Rectangles
470: ==========
471:
472: The rectangle commands affect rectangular areas of the text: all the
473: characters between a certain pair of columns, in a certain range of lines.
474: Commands are provided to kill rectangles, yank killed rectangles, clear
475: them out, or delete them. Rectangle commands are useful with text in
476: multicolumnar formats, such as perhaps code with comments at the right,
477: or for changing text into or out of such formats.
478:
479: When you must specify a rectangle for a command to work on, you do
480: it by putting the mark at one corner and point at the opposite corner.
481: The rectangle thus specified is called the "region-rectangle"
482: because it is controlled about the same way the region is controlled.
483: But remember that a given combination of point and mark values can be
484: interpreted either as specifying a region or as specifying a
485: rectangle; it is up to the command that uses them to choose the
486: interpretation.
487:
488: `M-x delete-rectangle'
489: Delete the text of the region-rectangle, moving any following text on
490: each line leftward to the left edge of the region-rectangle.
491: `M-x kill-rectangle'
492: Similar, but also save the contents of the region-rectangle as the
493: "last killed rectangle".
494: `M-x yank-rectangle'
495: Yank the last killed rectangle with its upper left corner at point.
496: `M-x open-rectangle'
497: Insert blank space to fill the space of the region-rectangle.
498: The previous contents of the region-rectangle are pushed rightward.
499: `M-x clear-rectangle'
500: Clear the region-rectangle by replacing its contents with spaces.
501:
502: The rectangle operations fall into two classes: commands deleting and
503: moving rectangles, and commands for blank rectangles.
504:
505: There are two ways to get rid of the text in a rectangle: you can discard
506: the text (delete it) or save it as the "last killed" rectangle. The
507: commands for these two ways are `M-x delete-rectangle' and `M-x
508: kill-rectangle'. In either case, the portion of each line that falls inside
509: the rectangle's boundaries is deleted, causing following text (if any) on
510: the line to move left.
511:
512: Note that "killing" a rectangle is not killing in the usual sense; the
513: rectangle is not stored in the kill ring, but in a special place that
514: can only record the most recent rectangle killed. This is because yanking
515: a rectangle is so different from yanking linear text that different yank
516: commands have to be used and yank-popping is hard to make sense of.
517:
518: Inserting a rectangle is the opposite of deleting one. All you need to
519: specify is where to put the upper left corner; that is done by putting
520: point there. The rectangle's first line is inserted there, the rectangle's
521: second line is inserted at a point one line vertically down, and so on.
522: The number of lines affected is determined by the height of the saved
523: rectangle.
524:
525: To insert the last killed rectangle, type `M-x yank-rectangle'.
526: This can be used to convert single-column lists into double-column
527: lists; kill the second half of the list as a rectangle and then
528: yank it beside the first line of the list.
529:
530: There are two commands for working with blank rectangles: `M-x
531: clear-rectangle' to blank out existing text, and `M-x open-rectangle'
532: to insert a blank rectangle. Clearing a rectangle is equivalent to
533: deleting it and then inserting as blank rectangle of the same size.
534:
535: Rectangles can also be copied into and out of registers.
536: *Note Rectangle Registers: RegRect.
537:
538:
539: File: emacs Node: Registers, Prev: Rectangles, Up: Top, Next: Display
540:
541: Registers
542: *********
543:
544: Emacs "registers" are places you can save text or positions for
545: later use. Text saved in a register can be copied into the buffer
546: once or many times; a position saved in a register is used by moving
547: point to that position. Rectangles can also be copied into and out of
548: registers (*Note Rectangles::).
549:
550: Each register has a name, which is a single character. A register can
551: store either a piece of text or a position or a rectangle, but only one
552: thing at any given time. Whatever you store in a register remains
553: there until you store something else in that register.
554:
555: * Menu:
556:
557: * RegPos:: Saving positions in registers.
558: * RegText:: Saving text in registers.
559: * RegRect:: Saving rectangles in registers.
560:
561: `M-x view-register RET R'
562: Display a description of what register R contains.
563:
564: `M-x view-register' reads a register name as an argument and then
565: displays the contents of the specified register.
566:
567:
568: File: emacs Node: RegPos, Prev: Registers, Up: Registers, Next: RegText
569:
570: Saving Positions in Registers
571: =============================
572:
573: Saving a position records a spot in a buffer so that you can move
574: back there later. Moving to a saved position reselects the buffer
575: and moves point to the spot.
576:
577: `C-x / R'
578: Save location of point in register R (`point-to-register').
579: `C-x j R'
580: Jump to the location saved in register R (`register-to-point').
581:
582: To save the current location of point in a register, choose a name R and
583: type `C-x / R'. The register R retains the location thus saved until you
584: store something else in that register.
585:
586: The command `C-x j R' moves point to the location recorded
587: in register R. The register is not affected; it continues to
588: record the same location. You can jump to the same position using the
589: same register any number of times.
590:
591:
592: File: emacs Node: RegText, Prev: RegPos, Up: Registers, Next: RegRect
593:
594: Saving Text in Registers
595: ========================
596:
597: When you want to insert a copy of the same piece of text frequently, it
598: may be impractical to use the kill ring, since each subsequent kill moves
599: the piece of text further down on the ring. It becomes hard to keep track
600: of what argument is needed to retrieve the same text with `C-y'. An
601: alternative is to store the text in a register with `C-x x'
602: (`copy-to-register') and then retrieve it with `C-x g'
603: (`insert-register').
604:
605: `C-x x R'
606: Copy region into register R (`copy-to-register').
607: `C-x g R'
608: Insert text contents of register R (`insert-register').
609:
610: `C-x x R' stores a copy of the text of the region into the
611: register named R. Given a numeric argument, `C-x x' deletes the
612: text from the buffer as well.
613:
614: `C-x g R' inserts in the buffer the text from register R.
615: Normally it leaves point before the text and places the mark after, but
616: with a numeric argument it puts point after the text and the mark before.
617:
618:
619: File: emacs Node: RegRect, Prev: RegText, Up: Registers
620:
621: Saving Rectangles in Registers
622: ==============================
623:
624: A register can contain a rectangle instead of linear text. The rectangle
625: is represented as a list of strings. *Note Rectangles::, for basic
626: information on rectangles and how rectangles in the buffer are specified.
627:
628: `C-x r R'
629: Copy the region-rectangle into register R (`copy-region-to-rectangle').
630: With numeric argument, delete it as well.
631: `C-x g R'
632: Insert the rectangle stored in register R (if it contains a
633: rectangle) (`insert-register').
634:
635: The `C-x g' command inserts linear text if the register contains
636: that, or inserts a rectangle if the register contains one.
637:
638:
639: File: emacs Node: Display, Prev: Registers, Up: Top, Next: Search
640:
641: Controlling the Display
642: ***********************
643:
644: Since only part of a large buffer fits in the window, Emacs tries to show
645: the part that is likely to be interesting. The display control commands
646: allow you to specify which part of the text you want to see.
647:
648: `C-l'
649: Clear screen and redisplay, scrolling the selected window to center
650: point vertically within it (`recenter').
651: `C-v'
652: Scroll forward (a windowful or a specified number of lines) (`scroll-up').
653: `M-v'
654: Scroll backward (`scroll-down').
655: `ARG C-l'
656: Scroll so point is on line ARG (`recenter').
657: `C-x <'
658: Scroll text in current window to the left (`scroll-left').
659: `C-x >'
660: Scroll to the right (`scroll-right').
661: `C-x $'
662: Make deeply indented lines invisible (`set-selective-display').
663:
664: * Menu:
665:
666: * Scrolling:: Moving text up and down in a window.
667: * Horizontal Scrolling:: Moving text left and right in a window.
668: * Selective Display:: Hiding lines with lots of indentation.
669: * Display Vars:: Information on variables for customizing display.
670:
671:
672: File: emacs Node: Scrolling, Prev: Display, Up: Display, Next: Horizontal Scrolling
673:
674: Scrolling
675: =========
676:
677: If a buffer contains text that is too large to fit entirely within a
678: window that is displaying the buffer, Emacs shows a contiguous section of
679: the text. The section shown always contains point.
680:
681: "Scrolling" means moving text up or down in the window so that
682: different parts of the text are visible. Scrolling forward means that text
683: moves up, and new text appears at the bottom. Scrolling backward moves
684: text down and new text appears at the top.
685:
686: Scrolling happens automatically if you move point past the bottom or top
687: of the window. You can also explicitly request scrolling with the commands
688: in this section.
689:
690:
691: `C-l'
692: Clear screen and redisplay, scrolling the selected window to center
693: point vertically within it (`recenter').
694: `C-v'
695: Scroll forward (a windowful or a specified number of lines) (`scroll-up').
696: `M-v'
697: Scroll backward (`scroll-down').
698: `ARG C-l'
699: Scroll so point is on line ARG (`recenter').
700:
701: The most basic scrolling command is `C-l' (`recenter') with no
702: argument. It clears the entire screen and redisplays all windows. In
703: addition, the selected window is scrolled so that point is halfway down
704: from the top of the window.
705:
706: The scrolling commands `C-v' and `M-v' let you move all the text in the
707: window up or down a few lines. `C-v' (`scroll-up') with an argument shows
708: you that many more lines at the bottom of the window, moving the text and
709: point up together as `C-l' might. `C-v' with a negative argument shows you
710: more lines at the top of the window. `Meta-v' (`scroll-down') is like
711: `C-v', but moves in the opposite direction.
712:
713: To read the buffer a windowful at a time, use `C-v' with no argument.
714: It takes the last two lines at the bottom of the window and puts them at
715: the top, followed by nearly a whole windowful of lines not previously
716: visible. If point was in the text scrolled off the top, it moves to the
717: new top of the window. `M-v' with no argument moves backward with
718: overlap similarly. The number of lines of overlap across a `C-v' or
719: `M-v' is controlled by the variable `next-screen-context-lines'; by
720: default, it is two.
721:
722: Another way to do scrolling is with `C-l' with a numeric argument.
723: `C-l' does not clear the screen when given an argument; it only scrolls
724: the selected window. With a positive argument N, it repositions text
725: to put point N lines down from the top. An argument of zero puts
726: point on the very top line. Point does not move with respect to the text;
727: rather, the text and point move rigidly on the screen. `C-l' with a
728: negative argument puts point that many lines from the bottom of the window.
729: For example, `C-u - 1 C-l' puts point on the bottom line, and `C-u
730: - 5 C-l' puts it five lines from the bottom. Just `C-u' as argument,
731: as in `C-u C-l', scrolls point to the center of the screen.
732:
733: Scrolling happens automatically if point has moved out of the visible
734: portion of the text when it is time to display. Usually the scrolling is
735: done so as to put point vertically centered within the window. However, if
736: the variable `scroll-step' has a nonzero value, an attempt is made to
737: scroll the buffer by that many lines; if that is enough to bring point back
738: into visibility, that is what is done.
739:
740:
741: File: emacs Node: Horizontal Scrolling, Prev: Scrolling, Up: Display
742:
743: Horizontal Scrolling
744: ====================
745:
746:
747: `C-x <'
748: Scroll text in current window to the left (`scroll-left').
749: `C-x >'
750: Scroll to the right (`scroll-right').
751:
752: The text in a window can also be scrolled horizontally. This means that
753: each line of text is shifted sideways in the window, and one or more
754: characters at the beginning of each line are not displayed at all. When a
755: window has been scrolled horizontally in this way, text lines are truncated
756: rather than continued (*Note Continuation Lines::), with a `$' appearing
757: in the first column when there is text truncated to the left, and in the
758: last column when there is text truncated to the right.
759:
760: The command `C-x <' (`scroll-left') scrolls the selected window
761: to the left by N columns with argument N. With no argument, it scrolls
762: by almost the full width of the window (two columns less, to be precise).
763: `C-x >' (`scroll-right') scrolls similarly to the right.
764: The window cannot be scrolled any farther to the right once it is
765: displaying normally (with each line starting at the window's left margin);
766: attempting to do so has no effect.
767:
768:
769: File: emacs Node: Selective Display, Prev: Display, Up: Display, Next: Display Vars
770:
771: Selective Display
772: =================
773:
774: Emacs has the ability to hide lines indented more than a certain number
775: of columns (you specify how many columns). You can use this to get an
776: overview of a part of a program.
777:
778: To hide lines, type `C-x $' (`set-selective-display') with a numeric
779: argument N. (*Note Arguments::, for how to give the argument.) Then lines
780: with at least N columns of indentation disappear from the screen. The only
781: indication of their presence is that three dots (`...') appear at the end
782: of each visible line that is followed by one or more invisible ones.
783:
784: The invisible lines are still present in the buffer, and most editing
785: commands see them as usual, so it is very easy to put point in the middle
786: of invisible text. When this happens, the cursor appears at the end of the
787: previous line, after the three dots. If point is at the end of the visible
788: line, before the newline that ends it, the cursor appears before the three
789: dots.
790:
791: The commands `C-n' and `C-p' move across the invisible lines as if they
792: were not there.
793:
794: To make everything visible again, type `C-x $' with no argument.
795:
796:
797: File: emacs Node: Display Vars, Prev: Selective Display, Up: Display
798:
799: Variables Controlling Display
800: =============================
801:
802: This section contains information for customization only. Beginning
803: users should skip it.
804:
805: The variable `mode-line-inverse-video' controls whether the mode
806: line is displayed in inverse video (assuming the terminal supports it);
807: `nil' means don't do so. *Note Mode Line::.
808:
809: If the variable `inverse-video' is non-`nil', Emacs attempts
810: to invert all the lines of the display from what they normally are.
811:
812: If the variable `visible-bell' is non-`nil', Emacs attempts to make the
813: whole screen blink when it would normally make an audible bell sound. This
814: variable has no effect if your terminal does not have a way to make the
815: screen blink.
816:
817: When you reenter Emacs after suspending, Emacs normally clears the screen
818: and redraws the entire display. On some terminals with more than one page
819: of memory, it is possible to arrange the termcap entry so that the
820: `ti' and `te' strings (output to the terminal when Emacs is
821: entered and exited, respectively) switch between pages of memory so as to
822: use one page for Emacs and another page for other output. Then you might
823: want to set the variable `no-redraw-on-reenter' non-`nil' so that
824: Emacs will assume, when resumed, that the screen page it is using still
825: contains what Emacs last wrote there.
826:
827: The variable `echo-keystrokes' controls the echoing of multi-character
828: keys; its value is the number of seconds of pause required to cause echoing
829: to start, or zero meaning don't echo at all. *Note Echo Area::.
830:
831: If the variable `ctl-arrow' is `nil', control characters in the
832: buffer are displayed with octal escape sequences, all except newline and
833: tab. Altering the value of `ctl-arrow' makes it local to the current
834: buffer; until that time, the default value is in effect. The default is
835: initially `t'. *Note Locals::.
836:
837: Normally, a tab character in the buffer is displayed as whitespace which
838: extends to the next display tab stop position, and display tab stops come
839: at intervals equal to eight spaces. The number of spaces per tab is
840: controlled by the variable `tab-width', which is made local by
841: changing it, just like `ctl-arrow'. Note that how the tab character
842: in the buffer is displayed has nothing to do with the definition of
843: TAB as a command.
844:
845: If you set the variable `selective-display-ellipses' to `nil',
846: the three dots do not appear at the end of a line that precedes invisible
847: lines. Then there is no visible indication of the invisible lines.
848: This variable too becomes local automatically when set.
849:
850:
851: File: emacs Node: Search, Prev: Display, Up: Top, Next: Fixit
852:
853: Searching and Replacement
854: *************************
855:
856: Like other editors, Emacs has commands for searching for occurrences of
857: a string. The principal search command is unusual in that it is
858: "incremental"; it begins to search before you have finished typing the
859: search string. There are also nonincremental search commands more like
860: those of other editors.
861:
862: Besides the usual `replace-string' command that finds all
863: occurrences of one string and replaces them with another, Emacs has a fancy
864: replacement command called `query-replace' which asks interactively
865: which occurrences to replace.
866:
867: * Menu:
868:
869: * Incremental Search:: Search happens as you type the string.
870: * Nonincremental Search:: Specify entire string and then search.
871: * Word Search:: Search for sequence of words.
872: * Regexp Search:: Search for match for a regexp.
873: * Regexps:: Syntax of regular expressions.
874: * Search Case:: To ignore case while searching, or not.
875: * Replace:: Search, and replace some or all matches.
876: * Other Repeating Search:: Operating on all matches for some regexp.
877:
878:
879: File: emacs Node: Incremental Search, Prev: Search, Up: Search, Next: Nonincremental Search
880:
881: Incremental Search
882: ==================
883:
884: An incremental search begins searching as soon as you type the first
885: character of the search string. As you type in the search string, Emacs
886: shows you where the string (as you have typed it so far) would be found.
887: When you have typed enough characters to identify the place you want, you
888: can stop. Depending on what you will do next, you may or may not need to
889: terminate the search explicitly with an ESC first.
890:
891: `C-s'
892: Incremental search forward (`isearch-forward').
893: `C-r'
894: Incremental search backward (`isearch-backward').
895:
896: `C-s' starts an incremental search. `C-s' reads characters from the
897: keyboard and positions the cursor at the first occurrence of the characters
898: that you have typed. If you type `C-s' and then `F', the cursor moves
899: right after the first `F'. Type an `O', and see the cursor move to after
900: the first `FO'. After another `O', the cursor is after the first `FOO'
901: after the place where you started the search. Meanwhile, the search string
902: `FOO' has been echoed in the echo area.
903:
904: The echo area display ends with three dots when actual searching is going
905: on. When search is waiting for more input, the three dots are removed.
906: (On slow terminals, the three dots are not displayed.)
907:
908: If you make a mistake in typing the search string, you can erase
909: characters with DEL. Each DEL cancels the last character of search string.
910: This does not happen until Emacs is ready to read another input character;
911: first it must either find, or fail to find, the character you want to
912: erase. If you do not want to wait for this to happen, use `C-g' as
913: described below.
914:
915: When you are satisfied with the place you have reached, you can type
916: ESC, which stops searching, leaving the cursor where the search
917: brought it. Also, any command not specially meaningful in searches stops
918: the searching and is then executed. Thus, typing `C-a' would exit the
919: search and then move to the beginning of the line. ESC is necessary
920: only if the next command you want to type is a printing character,
921: DEL, ESC, or another control character that is special within
922: searches (`C-q', `C-w', `C-r', `C-s' or `C-y').
923:
924: Sometimes you search for `FOO' and find it, but not the one you
925: expected to find. There was a second `FOO' that you forgot about,
926: before the one you were looking for. In this event, type another `C-s'
927: to move to the next occurrence of the search string. This can be done any
928: number of times. If you overshoot, you can cancel some `C-s'
929: characters with DEL.
930:
931: After you exit a search, you can search for the same string again by
932: typing just `C-s C-s': the first `C-s' is the key that invokes
933: incremental search, and the second `C-s' means "search again".
934:
935: If your string is not found at all, the echo area says `Failing
936: I-Search'. The cursor is after the place where Emacs found as much of your
937: string as it could. Thus, if you search for `FOOT', and there is no
938: `FOOT', you might see the cursor after the `FOO' in `FOOL'.
939: At this point there are several things you can do. If your string was
940: mistyped, you can rub some of it out and correct it. If you like the place
941: you have found, you can type ESC or some other Emacs command to
942: "accept what the search offered". Or you can type `C-g', which
943: removes from the search string the characters that could not be found (the
944: `T' in `FOOT'), leaving those that were found (the `FOO' in
945: `FOOT'). A second `C-g' at that point cancels the search
946: entirely, returning point to where it was when the search started.
947:
948: If a search is failing and you ask to repeat it by typing another
949: `C-s', it starts again from the beginning of the buffer. Repeating
950: a failing reverse search with `C-r' starts again from the end. This
951: is called "wrapping around". `Wrapped' appears in the search
952: prompt once this has happened.
953:
954: The `C-g' "quit" character does special things during searches;
955: just what it does depends on the status of the search. If the search has
956: found what you specified and is waiting for input, `C-g' cancels the
957: entire search. The cursor moves back to where you started the search. If
958: `C-g' is typed when there are characters in the search string that have
959: not been found---because Emacs is still searching for them, or because it
960: has failed to find them---then the search string characters which have not
961: been found are discarded from the search string. With them gone, the
962: search is now successful and waiting for more input, so a second `C-g'
963: will cancel the entire search.
964:
965: To search for a control character such as `C-s' or DEL or ESC,
966: you must quote it by typing `C-q' first. This function of `C-q' is
967: analogous to its meaning as an Emacs command: it causes the following
968: character to be treated the way a graphic character would normally be
969: treated in the same context.
970:
971: You can change to searching backwards with `C-r'. If a search fails
972: because the place you started was too late in the file, you should do this.
973: Repeated `C-r' keeps looking for more occurrences backwards. A
974: `C-s' starts going forwards again. `C-r' in a search can be cancelled
975: with DEL.
976:
977: If you know initially that you want to search backwards, you can
978: use `C-r' instead of `C-s' to start the search, because `C-r'
979: is also a key running a command (`isearch-backward') to search
980: backward.
981:
982: The characters `C-y' and `C-w' can be used in incremental search
983: to grab text from the buffer into the search string. This makes it
984: convenient to search for another occurrence of text at point. `C-w'
985: copies the word after point as part of the search string, advancing
986: point over that word. Another `C-s' to repeat the search will then
987: search for a string including that word. `C-y' is similar to `C-w'
988: but copies all the rest of the current line into the search string.
989:
990: All the characters special in incremental search can be changed by setting
991: the following variables:
992:
993: `search-delete-char'
994: Character to delete from incremental search string (normally DEL).
995: `search-exit-char'
996: Character to exit incremental search (normally ESC).
997: `search-quote-char'
998: Character to quote special characters for incremental search (normally
999: `C-q').
1000: `search-repeat-char'
1001: Character to repeat incremental search forwards (normally `C-s').
1002: `search-reverse-char'
1003: Character to repeat incremental search backwards (normally `C-r').
1004: `search-yank-line-char'
1005: Character to pull rest of line from buffer into search string
1006: (normally `C-y').
1007: `search-yank-word-char'
1008: Character to pull next word from buffer into search string (normally
1009: `C-w').
1010:
1011:
1012: Slow Terminal Incremental Search
1013: --------------------------------
1014:
1015: Incremental search on a slow terminal uses a modified style of display
1016: that is designed to take less time. Instead of redisplaying the buffer at
1017: each place the search gets to, it creates a new single-line window and uses
1018: that to display the line that the search has found. The single-line window
1019: comes into play as soon as point gets outside of the text that is already
1020: on the screen.
1021:
1022: When the search is terminated, the single-line window is removed. Only
1023: at this time is the window in which the search was done redisplayed to show
1024: its new value of point.
1025:
1026: The three dots at the end of the search string, normally used to indicate
1027: that searching is going on, are not displayed in slow style display.
1028:
1029: The slow terminal style of display is used when the terminal baud rate is
1030: less than or equal to the value of the variable `search-slow-speed',
1031: initially 1200.
1032:
1033: The number of lines to use in slow terminal search display is controlled
1034: by the variable `search-slow-window-lines'. 1 is its normal value.
1035:
1036:
1037: File: emacs Node: Nonincremental Search, Prev: Incremental Search, Up: Search, Next: Word Search
1038:
1039: Nonincremental Search
1040: =====================
1041:
1042: Emacs also has conventional nonincremental search commands, which require
1043: you to type the entire search string before searching begins.
1044:
1045: `C-s ESC STRING RET'
1046: Search for STRING.
1047: `C-r ESC STRING RET'
1048: Search backward for STRING.
1049:
1050: To do a nonincremental search, first type `C-s ESC'. This
1051: enters the minibuffer to read the search string; terminate the string with
1052: RET, and then the search is done. If the string is not found the
1053: search command gets an error.
1054:
1055: The way `C-s ESC' works is that the `C-s' invokes
1056: incremental search, which is specially programmed to invoke nonincremental
1057: search if the argument you give it is empty. (Such an empty argument would
1058: otherwise be useless.) `C-r ESC' also works this way.
1059:
1060: Forward and backward nonincremental searches are implemented by the
1061: commands `search-forward' and `search-backward'. These commands
1062: may be bound to keys in the usual manner. The reason that incremental
1063: search is programmed to invoke them as well is that `C-s ESC'
1064: is the traditional sequence of characters used in Emacs to invoke
1065: nonincremental search.
1066:
1067: However, nonincremental searches performed using `C-s ESC' do
1068: not call `search-forward' right away. The first thing done is to see
1069: if the next character is `C-w', which requests a word search.
1070:
1071: *Note Word Search::.
1072:
1073:
1074: File: emacs Node: Word Search, Prev: Nonincremental Search, Up: Search, Next: Regexp Search
1075:
1076: Word Search
1077: ===========
1078:
1079: Word search searches for a sequence of words without regard to how the
1080: words are separated. More precisely, you type a string of many words,
1081: using single spaces to separate them, and the string can be found even if
1082: there are multiple spaces, newlines or other punctuation between the words.
1083:
1084: Word search is useful in editing documents formatted by text formatters.
1085: If you edit while looking at the printed, formatted version, you can't tell
1086: where the line breaks are in the source file. With word search, you can
1087: search without having to know them.
1088:
1089: `C-s ESC C-w WORDS RET'
1090: Search for WORDS, ignoring differences in punctuation.
1091: `C-r ESC C-w WORDS RET'
1092: Search backward for WORDS, ignoring differences in punctuation.
1093:
1094: Word search is a special case of nonincremental search and is invoked
1095: with `C-s ESC C-w'. This is followed by the search string, which
1096: must always be terminated with RET. Being nonincremental, this
1097: search does not start until the argument is terminated. It works by
1098: constructing a regular expression and searching for that. *Note Regexp Search::.
1099:
1100: A backward word search can be done by `C-r ESC C-w'.
1101:
1102: Forward and backward word searches are implemented by the commands
1103: `word-search-forward' and `word-search-backward'. These commands
1104: may be bound to keys in the usual manner. The reason that incremental
1105: search is programmed to invoke them as well is that `C-s ESC C-w'
1106: is the traditional Emacs sequence of keys for word search.
1107:
1108:
1109: File: emacs Node: Regexp Search, Prev: Word Search, Up: Search, Next: Regexps
1110:
1111: Regular Expression Search
1112: =========================
1113:
1114: A "regular expression" ("regexp", for short) is a pattern that
1115: denotes a set of strings, possibly an infinite set. Searching for matches
1116: for a regexp is a very powerful operation that editors on Unix systems have
1117: traditionally offered. In GNU Emacs, you can search for the next match for
1118: a regexp either incrementally or not.
1119:
1120: Incremental search for a regexp is done by typing `C-M-s'
1121: (`isearch-forward-regexp'). This command reads a search string
1122: incrementally just like `C-s', but it treats the search string as a
1123: regexp rather than looking for an exact match against the text in the
1124: buffer. Each time you add text to the search string, you make the regexp
1125: longer, and the new regexp is searched for. A reverse regexp search command
1126: `isearch-backward-regexp' also exists but no key runs it.
1127:
1128: All of the control characters that do special things within an ordinary
1129: incremental search have the same function in incremental regexp search.
1130: Typing `C-s' or `C-r' immediately after starting the search
1131: retrieves the last incremental search regexp used; that is to say,
1132: incremental regexp and non-regexp searches have independent defaults.
1133:
1134: Note that adding characters to the regexp in an incremental regexp search
1135: does not make the cursor move back and start again. Perhaps it ought to; I
1136: am not sure. As it stands, if you have searched for `foo' and you
1137: add `\|bar', the search will not check for a `bar' in the
1138: buffer before the `foo'.
1139:
1140: Nonincremental search for a regexp is done by the functions
1141: `re-search-forward' and `re-search-backward'. You can invoke
1142: these with `M-x', or bind them to keys. Also, you can call
1143: `re-search-forward' by way of incremental regexp search with
1144: `C-M-s ESC'.
1145:
1146:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.