Commit | Line | Data |
---|---|---|
8cf51b2c GM |
1 | @c This is part of the Emacs manual. |
2 | @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2001, 2002, | |
5df4f04c | 3 | @c 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
8cf51b2c GM |
4 | @c See file emacs.texi for copying conditions. |
5 | @node Fixit, Keyboard Macros, Search, Top | |
6 | @chapter Commands for Fixing Typos | |
7 | @cindex typos, fixing | |
8 | @cindex mistakes, correcting | |
9 | ||
bc129797 CY |
10 | In this chapter we describe the commands that are especially useful |
11 | when you catch a mistake in your text after you have made it, or | |
12 | change your mind while composing text on the fly. | |
8cf51b2c GM |
13 | |
14 | The most fundamental command for correcting erroneous editing is the | |
bc129797 CY |
15 | undo command @kbd{C-/} (which is also bound to @kbd{C-x u} and |
16 | @kbd{C-_}). This undoes a single command, or a part of a command (as | |
17 | in the case of @code{query-replace}), or several consecutive | |
18 | self-inserting characters. Consecutive repetitions of @kbd{C-/} undo | |
19 | earlier and earlier changes, back to the limit of the undo information | |
20 | available. | |
21 | ||
22 | Aside from the commands described here, you can erase text using | |
23 | deletion commands such as @key{DEL} (@code{delete-backward-char}). | |
24 | These were described earlier in this manual. @xref{Erasing}. | |
8cf51b2c GM |
25 | |
26 | @menu | |
27 | * Undo:: The Undo commands. | |
8cf51b2c GM |
28 | * Transpose:: Exchanging two characters, words, lines, lists... |
29 | * Fixing Case:: Correcting case of last word entered. | |
30 | * Spelling:: Apply spelling checker to a word, or a whole file. | |
31 | @end menu | |
32 | ||
33 | @node Undo | |
34 | @section Undo | |
35 | @cindex undo | |
36 | @cindex changes, undoing | |
37 | ||
bc129797 | 38 | The @dfn{undo} command reverses recent changes in the buffer's text. |
8cf51b2c GM |
39 | Each buffer records changes individually, and the undo command always |
40 | applies to the current buffer. You can undo all the changes in a | |
bc129797 | 41 | buffer for as far as back its records go. Usually, each editing |
8cf51b2c GM |
42 | command makes a separate entry in the undo records, but some commands |
43 | such as @code{query-replace} divide their changes into multiple | |
bc129797 CY |
44 | entries for flexibility in undoing. Consecutive character insertion |
45 | commands are usually grouped together into a single undo record, to | |
46 | make undoing less tedious. | |
8cf51b2c GM |
47 | |
48 | @table @kbd | |
bc129797 CY |
49 | @item C-/ |
50 | @itemx C-x u | |
8cf51b2c | 51 | @itemx C-_ |
8cf51b2c GM |
52 | Undo one entry in the current buffer's undo records (@code{undo}). |
53 | @end table | |
54 | ||
55 | @kindex C-x u | |
56 | @kindex C-_ | |
57 | @kindex C-/ | |
58 | @findex undo | |
bc129797 CY |
59 | To begin to undo, type @kbd{C-/} (or its aliases, @kbd{C-_} or |
60 | @kbd{C-x u})@footnote{Aside from @kbd{C-/}, the @code{undo} command is | |
61 | also bound to @kbd{C-x u} because that is more straightforward for | |
62 | beginners to remember: @samp{u} stands for ``undo''. It is also bound | |
63 | to @kbd{C-_} because typing @kbd{C-/} on some text-only terminals | |
64 | actually enters @kbd{C-_}.}. This undoes the most recent change in | |
65 | the buffer, and moves point back to where it was before that change. | |
8cf51b2c | 66 | |
a7cdd618 | 67 | Consecutive repetitions of @kbd{C-/} (or its aliases) undo earlier |
bc129797 CY |
68 | and earlier changes in the current buffer. If all the recorded |
69 | changes have already been undone, the undo command signals an error. | |
8cf51b2c | 70 | |
bc129797 | 71 | @cindex redo |
8cf51b2c GM |
72 | @findex undo-only |
73 | Any command other than an undo command breaks the sequence of undo | |
bc129797 CY |
74 | commands. Starting from that moment, the entire sequence of undo |
75 | commands that you have just performed are themselves placed into the | |
76 | undo record, as a single set of changes. Therefore, to re-apply | |
77 | changes you have undone, type @kbd{C-f} or any other command that | |
78 | harmlessly breaks the sequence of undoing; then type @kbd{C-/} to undo | |
79 | the undo command. | |
80 | ||
81 | On the other hand, if you want to resume undoing, without redoing | |
82 | previous undo commands, use @kbd{M-x undo-only}. This is like | |
83 | @code{undo}, but will not redo changes you have just undone. | |
84 | ||
85 | If you notice that a buffer has been modified accidentally, the | |
86 | easiest way to recover is to type @kbd{C-/} repeatedly until the stars | |
87 | disappear from the front of the mode line (@pxref{Mode Line}). | |
88 | Whenever an undo command makes the stars disappear from the mode line, | |
89 | it means that the buffer contents are the same as they were when the | |
90 | file was last read in or saved. If you do not remember whether you | |
91 | changed the buffer deliberately, type @kbd{C-/} once. When you see | |
92 | the last change you made undone, you will see whether it was an | |
93 | intentional change. If it was an accident, leave it undone. If it | |
94 | was deliberate, redo the change as described above. | |
8cf51b2c GM |
95 | |
96 | @cindex selective undo | |
a7cdd618 CY |
97 | @kindex C-u C-/ |
98 | When there is an active region, any use of @code{undo} performs | |
bc129797 | 99 | @dfn{selective undo}: it undoes the most recent change within the |
a7cdd618 CY |
100 | region, instead of the entire buffer. However, when Transient Mark |
101 | mode is off (@pxref{Persistent Mark}), @kbd{C-/} always operates on | |
102 | the entire buffer, ignoring the region. In this case, you can perform | |
103 | selective undo by supplying a prefix argument to the @code{undo} | |
bc129797 CY |
104 | command: @kbd{C-u C-/}. To undo further changes in the same region, |
105 | repeat the @code{undo} command (no prefix argument is needed). | |
8cf51b2c | 106 | |
bc129797 CY |
107 | Some specialized buffers do not make undo records. Buffers whose |
108 | names start with spaces never do; these buffers are used internally by | |
109 | Emacs to hold text that users don't normally look at or edit. | |
8cf51b2c GM |
110 | |
111 | @vindex undo-limit | |
112 | @vindex undo-strong-limit | |
113 | @vindex undo-outer-limit | |
114 | @cindex undo limit | |
bc129797 CY |
115 | When the undo records for a buffer becomes too large, Emacs discards |
116 | the oldest undo records from time to time (during @dfn{garbage | |
117 | collection}). You can specify how much undo records to keep by | |
118 | setting the variables @code{undo-limit}, @code{undo-strong-limit}, and | |
119 | @code{undo-outer-limit}. Their values are expressed in bytes. | |
8cf51b2c GM |
120 | |
121 | The variable @code{undo-limit} sets a soft limit: Emacs keeps undo | |
122 | data for enough commands to reach this size, and perhaps exceed it, | |
123 | but does not keep data for any earlier commands beyond that. Its | |
c43d9559 | 124 | default value is 80000. The variable @code{undo-strong-limit} sets a |
bc129797 CY |
125 | stricter limit: any previous command (though not the most recent one) |
126 | that pushes the size past this amount is forgotten. The default value | |
c43d9559 | 127 | of @code{undo-strong-limit} is 120000. |
8cf51b2c GM |
128 | |
129 | Regardless of the values of those variables, the most recent change | |
130 | is never discarded unless it gets bigger than @code{undo-outer-limit} | |
c43d9559 | 131 | (normally 12,000,000). At that point, Emacs discards the undo data and |
8cf51b2c GM |
132 | warns you about it. This is the only situation in which you cannot |
133 | undo the last command. If this happens, you can increase the value of | |
134 | @code{undo-outer-limit} to make it even less likely to happen in the | |
135 | future. But if you didn't expect the command to create such large | |
136 | undo data, then it is probably a bug and you should report it. | |
137 | @xref{Bugs,, Reporting Bugs}. | |
138 | ||
8cf51b2c GM |
139 | @node Transpose |
140 | @section Transposing Text | |
141 | ||
142 | @table @kbd | |
143 | @item C-t | |
144 | Transpose two characters (@code{transpose-chars}). | |
145 | @item M-t | |
146 | Transpose two words (@code{transpose-words}). | |
147 | @item C-M-t | |
148 | Transpose two balanced expressions (@code{transpose-sexps}). | |
149 | @item C-x C-t | |
150 | Transpose two lines (@code{transpose-lines}). | |
151 | @end table | |
152 | ||
153 | @kindex C-t | |
154 | @findex transpose-chars | |
155 | The common error of transposing two characters can be fixed, when they | |
156 | are adjacent, with the @kbd{C-t} command (@code{transpose-chars}). Normally, | |
157 | @kbd{C-t} transposes the two characters on either side of point. When | |
158 | given at the end of a line, rather than transposing the last character of | |
159 | the line with the newline, which would be useless, @kbd{C-t} transposes the | |
160 | last two characters on the line. So, if you catch your transposition error | |
161 | right away, you can fix it with just a @kbd{C-t}. If you don't catch it so | |
162 | fast, you must move the cursor back between the two transposed | |
163 | characters before you type @kbd{C-t}. If you transposed a space with | |
164 | the last character of the word before it, the word motion commands are | |
165 | a good way of getting there. Otherwise, a reverse search (@kbd{C-r}) | |
166 | is often the best way. @xref{Search}. | |
167 | ||
168 | @kindex C-x C-t | |
169 | @findex transpose-lines | |
170 | @kindex M-t | |
171 | @findex transpose-words | |
172 | @c Don't index C-M-t and transpose-sexps here, they are indexed in | |
173 | @c programs.texi, in the "List Commands" node. | |
174 | @c @kindex C-M-t | |
175 | @c @findex transpose-sexps | |
176 | @kbd{M-t} transposes the word before point with the word after point | |
177 | (@code{transpose-words}). It moves point forward over a word, | |
178 | dragging the word preceding or containing point forward as well. The | |
179 | punctuation characters between the words do not move. For example, | |
180 | @w{@samp{FOO, BAR}} transposes into @w{@samp{BAR, FOO}} rather than | |
181 | @samp{@w{BAR FOO,}}. | |
182 | ||
183 | @kbd{C-M-t} (@code{transpose-sexps}) is a similar command for | |
184 | transposing two expressions (@pxref{Expressions}), and @kbd{C-x C-t} | |
185 | (@code{transpose-lines}) exchanges lines. They work like @kbd{M-t} | |
186 | except as regards what units of text they transpose. | |
187 | ||
188 | A numeric argument to a transpose command serves as a repeat count: it | |
189 | tells the transpose command to move the character (word, expression, line) | |
190 | before or containing point across several other characters (words, | |
191 | expressions, lines). For example, @kbd{C-u 3 C-t} moves the character before | |
192 | point forward across three other characters. It would change | |
193 | @samp{f@point{}oobar} into @samp{oobf@point{}ar}. This is equivalent to | |
194 | repeating @kbd{C-t} three times. @kbd{C-u - 4 M-t} moves the word | |
195 | before point backward across four words. @kbd{C-u - C-M-t} would cancel | |
196 | the effect of plain @kbd{C-M-t}.@refill | |
197 | ||
198 | A numeric argument of zero is assigned a special meaning (because | |
199 | otherwise a command with a repeat count of zero would do nothing): to | |
200 | transpose the character (word, expression, line) ending after point | |
201 | with the one ending after the mark. | |
202 | ||
203 | @node Fixing Case | |
204 | @section Case Conversion | |
205 | ||
206 | @table @kbd | |
207 | @item M-- M-l | |
208 | Convert last word to lower case. Note @kbd{Meta--} is Meta-minus. | |
209 | @item M-- M-u | |
210 | Convert last word to all upper case. | |
211 | @item M-- M-c | |
212 | Convert last word to lower case with capital initial. | |
213 | @end table | |
214 | ||
215 | @kindex M-@t{-} M-l | |
216 | @kindex M-@t{-} M-u | |
217 | @kindex M-@t{-} M-c | |
218 | A very common error is to type words in the wrong case. Because of this, | |
219 | the word case-conversion commands @kbd{M-l}, @kbd{M-u} and @kbd{M-c} have a | |
220 | special feature when used with a negative argument: they do not move the | |
221 | cursor. As soon as you see you have mistyped the last word, you can simply | |
222 | case-convert it and go on typing. @xref{Case}.@refill | |
223 | ||
224 | @node Spelling | |
225 | @section Checking and Correcting Spelling | |
226 | @cindex spelling, checking and correcting | |
227 | @cindex checking spelling | |
228 | @cindex correcting spelling | |
229 | ||
bc129797 CY |
230 | This section describes the commands to check the spelling of a |
231 | single word or of a portion of a buffer. These commands only work if | |
349b3256 AM |
232 | the spelling checker program Aspell, Ispell or Hunspell is installed. |
233 | Aspell, Ispell or Hunspell are not part of Emacs, but one or the other | |
234 | is usually installed in GNU/Linux and other free operating systems. | |
8cf51b2c GM |
235 | @ifnottex |
236 | @xref{Top, Aspell,, aspell, The Aspell Manual}. | |
237 | @end ifnottex | |
238 | ||
239 | @table @kbd | |
8cf51b2c | 240 | @item M-$ |
bc129797 CY |
241 | Check and correct spelling of the active region or the word at point |
242 | (@code{ispell-word}). | |
8cf51b2c | 243 | @item M-x ispell |
bc129797 | 244 | Check and correct spelling in the active region or the entire buffer. |
8cf51b2c | 245 | @item M-x ispell-buffer |
bc129797 | 246 | Check and correct spelling in the buffer. |
8cf51b2c | 247 | @item M-x ispell-region |
bc129797 | 248 | Check and correct spelling in the region. |
8cf51b2c | 249 | @item M-x ispell-message |
bc129797 CY |
250 | Check and correct spelling in a draft mail message, excluding cited |
251 | material. | |
8cf51b2c | 252 | @item M-x ispell-change-dictionary @key{RET} @var{dict} @key{RET} |
349b3256 | 253 | Restart the Aspell/Ispell/Hunspell process, using @var{dict} as the dictionary. |
8cf51b2c | 254 | @item M-x ispell-kill-ispell |
349b3256 | 255 | Kill the Aspell/Ispell/Hunspell subprocess. |
bc129797 CY |
256 | @item M-@key{TAB} |
257 | @itemx @key{ESC} @key{TAB} | |
258 | Complete the word before point based on the spelling dictionary | |
259 | (@code{ispell-complete-word}). | |
260 | @item M-x flyspell-mode | |
261 | Enable Flyspell mode, which highlights all misspelled words. | |
262 | @item M-x flyspell-prog-mode | |
263 | Enable Flyspell mode for comments and strings only. | |
8cf51b2c GM |
264 | @end table |
265 | ||
8cf51b2c GM |
266 | @kindex M-$ |
267 | @findex ispell-word | |
268 | To check the spelling of the word around or before point, and | |
bc129797 CY |
269 | optionally correct it as well, type @kbd{M-$} (@code{ispell-word}). |
270 | If a region is active, @kbd{M-$} checks the spelling of all words | |
271 | within the region. @xref{Mark}. (When Transient Mark mode is off, | |
272 | @kbd{M-$} always acts on the word around or before point, ignoring the | |
273 | region. @xref{Persistent Mark}.) | |
a7cdd618 CY |
274 | |
275 | @findex ispell | |
8cf51b2c GM |
276 | @findex ispell-buffer |
277 | @findex ispell-region | |
bc129797 CY |
278 | @cindex spell-checking the active region |
279 | Similarly, the command @kbd{M-x ispell} performs spell-checking in | |
280 | the region if one is active, or in the entire buffer otherwise. The | |
281 | commands @kbd{M-x ispell-buffer} and @kbd{M-x ispell-region} | |
a7cdd618 | 282 | explicitly perform spell-checking on the entire buffer or the region |
bc129797 CY |
283 | respectively. To check spelling in an email message you are writing, |
284 | use @kbd{M-x ispell-message}; that command checks the whole buffer, | |
285 | except for material that is indented or appears to be cited from other | |
286 | messages. @xref{Sending Mail}. | |
a7cdd618 | 287 | |
bc129797 CY |
288 | When one of these commands encounters what appears to be an |
289 | incorrect word, it asks you what to do. It usually displays a list of | |
290 | numbered ``near-misses''---words that are close to the incorrect word. | |
291 | Then you must type a single-character response. Here are the valid | |
292 | responses: | |
8cf51b2c GM |
293 | |
294 | @table @kbd | |
bc129797 CY |
295 | @item @var{digit} |
296 | Replace the word, just this time, with one of the displayed | |
297 | near-misses. Each near-miss is listed with a digit; type that digit | |
298 | to select it. | |
299 | ||
8cf51b2c GM |
300 | @item @key{SPC} |
301 | Skip this word---continue to consider it incorrect, but don't change it | |
302 | here. | |
303 | ||
304 | @item r @var{new} @key{RET} | |
bc129797 | 305 | Replace the word, just this time, with @var{new}. (The replacement |
8cf51b2c GM |
306 | string will be rescanned for more spelling errors.) |
307 | ||
308 | @item R @var{new} @key{RET} | |
309 | Replace the word with @var{new}, and do a @code{query-replace} so you | |
310 | can replace it elsewhere in the buffer if you wish. (The replacements | |
311 | will be rescanned for more spelling errors.) | |
312 | ||
8cf51b2c GM |
313 | @item a |
314 | Accept the incorrect word---treat it as correct, but only in this | |
315 | editing session. | |
316 | ||
317 | @item A | |
318 | Accept the incorrect word---treat it as correct, but only in this | |
319 | editing session and for this buffer. | |
320 | ||
321 | @item i | |
349b3256 AM |
322 | Insert this word in your private dictionary file so that Aspell or Ispell |
323 | or Hunspell will consider it correct from now on, even in future sessions. | |
8cf51b2c | 324 | |
8cf51b2c GM |
325 | @item m |
326 | Like @kbd{i}, but you can also specify dictionary completion | |
327 | information. | |
328 | ||
bc129797 CY |
329 | @item u |
330 | Insert the lower-case version of this word in your private dic@-tion@-ary | |
331 | file. | |
332 | ||
8cf51b2c GM |
333 | @item l @var{word} @key{RET} |
334 | Look in the dictionary for words that match @var{word}. These words | |
335 | become the new list of ``near-misses''; you can select one of them as | |
336 | the replacement by typing a digit. You can use @samp{*} in @var{word} as a | |
337 | wildcard. | |
338 | ||
339 | @item C-g | |
bc129797 | 340 | @itemx X |
8cf51b2c GM |
341 | Quit interactive spell checking, leaving point at the word that was |
342 | being checked. You can restart checking again afterward with @kbd{C-u | |
343 | M-$}. | |
344 | ||
8cf51b2c GM |
345 | @item x |
346 | Quit interactive spell checking and move point back to where it was | |
347 | when you started spell checking. | |
348 | ||
349 | @item q | |
349b3256 AM |
350 | Quit interactive spell checking and kill the Aspell/Ispell/Hunspell |
351 | subprocess. | |
8cf51b2c | 352 | |
8cf51b2c GM |
353 | @item ? |
354 | Show the list of options. | |
355 | @end table | |
356 | ||
357 | @findex ispell-complete-word | |
bc129797 CY |
358 | In Text mode and related modes, the command @kbd{M-@key{TAB}} |
359 | (@code{ispell-complete-word}) shows a list of completions based on | |
360 | spelling correction. Insert the beginning of a word, and then type | |
361 | @kbd{M-@key{TAB}}; the command displays a completion list window. (If | |
362 | your window manager intercepts @kbd{M-@key{TAB}}, type @kbd{@key{ESC} | |
363 | @key{TAB}} or @kbd{C-M-i}.) To choose one of the completions listed, | |
364 | click @kbd{Mouse-2} or @kbd{Mouse-1} fast on it, or move the cursor | |
365 | there in the completions window and type @key{RET}. @xref{Text Mode}. | |
8cf51b2c GM |
366 | |
367 | @cindex @code{ispell} program | |
368 | @findex ispell-kill-ispell | |
349b3256 AM |
369 | Once started, the Aspell or Ispell or Hunspell subprocess continues |
370 | to run, waiting for something to do, so that subsequent spell checking | |
8cf51b2c GM |
371 | commands complete more quickly. If you want to get rid of the |
372 | process, use @kbd{M-x ispell-kill-ispell}. This is not usually | |
373 | necessary, since the process uses no time except when you do spelling | |
374 | correction. | |
375 | ||
376 | @vindex ispell-dictionary | |
6f591cf4 AM |
377 | @vindex ispell-local-dictionary |
378 | @vindex ispell-personal-dictionary | |
bc129797 | 379 | @vindex ispell-complete-word-dict |
349b3256 | 380 | Ispell, Aspell and Hunspell use two dictionaries together for spell checking: |
6f591cf4 AM |
381 | the standard dictionary and your private dictionary. The standard |
382 | dictionary is specified by @code{ispell-local-dictionary} or, | |
383 | if @code{nil}, by @code{ispell-dictionary}. If both are @code{nil} | |
384 | the default dictionary is selected. The command | |
385 | @kbd{M-x ispell-change-dictionary} sets the standard dictionary for | |
386 | the buffer and then restarts the subprocess, so that it will use a | |
387 | different standard dictionary. Personal dictionary is specified by | |
388 | @code{ispell-personal-dictionary}. If @code{nil}, default value is | |
389 | used. | |
390 | ||
391 | Set variable @code{ispell-dictionary} to select a specific default | |
392 | dictionary for all your documents. Set variable | |
393 | @code{ispell-local-dictionary} in the local variables section to | |
394 | select a specific dictionary for a given document. | |
395 | ||
396 | A separate dictionary is used for word completion. The variable | |
397 | @code{ispell-complete-word-dict} specifies the file name of this | |
398 | dictionary. The completion dictionary must be different because it | |
399 | cannot use root and affix information. For some languages, there | |
400 | is a spell checking dictionary but no word completion dictionary. | |
8cf51b2c | 401 | |
bc129797 CY |
402 | @cindex Flyspell mode |
403 | @findex flyspell-mode | |
404 | Flyspell mode is a fully-automatic way to check spelling as you edit | |
405 | in Emacs. It operates by checking words as you change or insert them. | |
406 | When it finds a word that it does not recognize, it highlights that | |
407 | word. This does not interfere with your editing, but when you see the | |
408 | highlighted word, you can move to it and fix it. Type @kbd{M-x | |
409 | flyspell-mode} to enable or disable this mode in the current buffer. | |
7f8dba73 RS |
410 | @findex turn-on-flyspell |
411 | To enable @code{flyspell-mode} in all text mode buffers, add | |
412 | @code{turn-on-flyspell} to @code{text-mode-hook}. | |
413 | ||
bc129797 CY |
414 | |
415 | When Flyspell mode highlights a word as misspelled, you can click on | |
416 | it with @kbd{Mouse-2} to display a menu of possible corrections and | |
417 | actions. You can also correct the word by editing it manually in any | |
418 | way you like. | |
419 | ||
420 | @findex flyspell-prog-mode | |
421 | Flyspell Prog mode works just like ordinary Flyspell mode, except | |
422 | that it only checks words in comments and string constants. This | |
423 | feature is useful for editing programs. Type @kbd{M-x | |
424 | flyspell-prog-mode} to enable or disable this mode in the current | |
425 | buffer. | |
426 | ||
8cf51b2c GM |
427 | @ignore |
428 | arch-tag: 3359a443-96ed-448f-9f05-c8111ba8eac0 | |
429 | @end ignore |