comparison man/search.texi @ 60860:c218b809efea

Delete explicit node pointers. (Incremental Search): New menu. (Basic Isearch, Repeat Isearch, Error in Isearch) (Non-Ascii Isearch, Isearch Yank, Highlight Isearch, Isearch Scroll) (Slow Isearch): New subnodes. (Configuring Scrolling): Node deleted. (Search Case): Doc default-case-fold-search. (Regexp Replace): Move replace-regexp doc here.
author Richard M. Stallman <rms@gnu.org>
date Wed, 23 Mar 2005 14:46:18 +0000
parents 856e8ee31fcb
children ce18be094148
comparison
equal deleted inserted replaced
60859:f3b502de01b6 60860:c218b809efea
23 * Nonincremental Search:: Specify entire string and then search. 23 * Nonincremental Search:: Specify entire string and then search.
24 * Word Search:: Search for sequence of words. 24 * Word Search:: Search for sequence of words.
25 * Regexp Search:: Search for match for a regexp. 25 * Regexp Search:: Search for match for a regexp.
26 * Regexps:: Syntax of regular expressions. 26 * Regexps:: Syntax of regular expressions.
27 * Search Case:: To ignore case while searching, or not. 27 * Search Case:: To ignore case while searching, or not.
28 * Configuring Scrolling:: Scrolling within incremental search.
29 * Replace:: Search, and replace some or all matches. 28 * Replace:: Search, and replace some or all matches.
30 * Other Repeating Search:: Operating on all matches for some regexp. 29 * Other Repeating Search:: Operating on all matches for some regexp.
31 @end menu 30 @end menu
32 31
33 @node Incremental Search, Nonincremental Search, Search, Search 32 @node Incremental Search
34 @section Incremental Search 33 @section Incremental Search
35 34
36 @cindex incremental search
37 An incremental search begins searching as soon as you type the first 35 An incremental search begins searching as soon as you type the first
38 character of the search string. As you type in the search string, Emacs 36 character of the search string. As you type in the search string, Emacs
39 shows you where the string (as you have typed it so far) would be 37 shows you where the string (as you have typed it so far) would be
40 found. When you have typed enough characters to identify the place you 38 found. When you have typed enough characters to identify the place you
41 want, you can stop. Depending on what you plan to do next, you may or 39 want, you can stop. Depending on what you plan to do next, you may or
46 @item C-s 44 @item C-s
47 Incremental search forward (@code{isearch-forward}). 45 Incremental search forward (@code{isearch-forward}).
48 @item C-r 46 @item C-r
49 Incremental search backward (@code{isearch-backward}). 47 Incremental search backward (@code{isearch-backward}).
50 @end table 48 @end table
49
50 @menu
51 * Basic Isearch:: Basic incremental search commands.
52 * Repeat Isearch:: Searching for the same string again.
53 * Error in Isearch:: When your string is not found.
54 * Special Isearch:: Special input in incremental search.
55 * Non-ASCII Isearch:: How to search for non-ASCII characters.
56 * Isearch Yank:: Commands that grab text into the search string
57 or else edit the search string.
58 * Highlight Isearch:: Isearch highlights the other possible matches.
59 * Isearch Scroll:: Scrolling during an incremental search.
60 * Slow Isearch:: Incremental search features for slow terminals.
61 @end menu
62
63 @node Basic Isearch
64 @subsection Basics of Incremental Search
65 @cindex incremental search
51 66
52 @kindex C-s 67 @kindex C-s
53 @findex isearch-forward 68 @findex isearch-forward
54 @kbd{C-s} starts a forward incremental search. It reads characters 69 @kbd{C-s} starts a forward incremental search. It reads characters
55 from the keyboard, and moves point past the next occurrence of those 70 from the keyboard, and moves point past the next occurrence of those
79 printing character, @key{DEL}, @key{RET}, or another character that is 94 printing character, @key{DEL}, @key{RET}, or another character that is
80 special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, 95 special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s},
81 @kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some other 96 @kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some other
82 meta-characters). 97 meta-characters).
83 98
99 When you exit the incremental search, it sets the mark where point
100 @emph{was} before the search. That is convenient for moving back
101 there. In Transient Mark mode, incremental search sets the mark
102 without activating it, and does so only if the mark is not already
103 active.
104
105 @node Repeat Isearch
106 @subsection Repeating Incremental Search
107
84 Sometimes you search for @samp{FOO} and find one, but not the one you 108 Sometimes you search for @samp{FOO} and find one, but not the one you
85 expected to find. There was a second @samp{FOO} that you forgot 109 expected to find. There was a second @samp{FOO} that you forgot
86 about, before the one you were aiming for. In this event, type 110 about, before the one you were aiming for. In this event, type
87 another @kbd{C-s} to move to the next occurrence of the search string. 111 another @kbd{C-s} to move to the next occurrence of the search string.
88 You can repeat this any number of times. If you overshoot, you can 112 You can repeat this any number of times. If you overshoot, you can
89 cancel some @kbd{C-s} characters with @key{DEL}. 113 cancel some @kbd{C-s} characters with @key{DEL}.
90 114
91 After you exit a search, you can search for the same string again by 115 After you exit a search, you can search for the same string again by
92 typing just @kbd{C-s C-s}: the first @kbd{C-s} is the key that invokes 116 typing just @kbd{C-s C-s}: the first @kbd{C-s} is the key that invokes
93 incremental search, and the second @kbd{C-s} means ``search again.'' 117 incremental search, and the second @kbd{C-s} means ``search again.''
118
119 If a search is failing and you ask to repeat it by typing another
120 @kbd{C-s}, it starts again from the beginning of the buffer.
121 Repeating a failing reverse search with @kbd{C-r} starts again from
122 the end. This is called @dfn{wrapping around}, and @samp{Wrapped}
123 appears in the search prompt once this has happened. If you keep on
124 going past the original starting point of the search, it changes to
125 @samp{Overwrapped}, which means that you are revisiting matches that
126 you have already seen.
94 127
95 To reuse earlier search strings, use the @dfn{search ring}. The 128 To reuse earlier search strings, use the @dfn{search ring}. The
96 commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a search 129 commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a search
97 string to reuse. These commands leave the selected search ring element 130 string to reuse. These commands leave the selected search ring element
98 in the minibuffer, where you can edit it. To edit the current search 131 in the minibuffer, where you can edit it. To edit the current search
99 string in the minibuffer without replacing it with items from the 132 string in the minibuffer without replacing it with items from the
100 search ring, type @kbd{M-e}. Type @kbd{C-s} or @kbd{C-r} 133 search ring, type @kbd{M-e}. Type @kbd{C-s} or @kbd{C-r}
101 to terminate editing the string and search for it. 134 to terminate editing the string and search for it.
135
136 You can change to searching backwards with @kbd{C-r}. If a search fails
137 because the place you started was too late in the file, you should do this.
138 Repeated @kbd{C-r} keeps looking for more occurrences backwards. A
139 @kbd{C-s} starts going forwards again. @kbd{C-r} in a search can be canceled
140 with @key{DEL}.
141
142 @kindex C-r
143 @findex isearch-backward
144 If you know initially that you want to search backwards, you can use
145 @kbd{C-r} instead of @kbd{C-s} to start the search, because @kbd{C-r} as
146 a key runs a command (@code{isearch-backward}) to search backward. A
147 backward search finds matches that are entirely before the starting
148 point, just as a forward search finds matches that begin after it.
149
150 @node Error in Isearch
151 @subsection Errors in Incremental Search
102 152
103 If your string is not found at all, the echo area says @samp{Failing 153 If your string is not found at all, the echo area says @samp{Failing
104 I-Search}. The cursor is after the place where Emacs found as much of your 154 I-Search}. The cursor is after the place where Emacs found as much of your
105 string as it could. Thus, if you search for @samp{FOOT}, and there is no 155 string as it could. Thus, if you search for @samp{FOOT}, and there is no
106 @samp{FOOT}, you might see the cursor after the @samp{FOO} in @samp{FOOL}. 156 @samp{FOOT}, you might see the cursor after the @samp{FOO} in @samp{FOOL}.
111 removes from the search string the characters that could not be found (the 161 removes from the search string the characters that could not be found (the
112 @samp{T} in @samp{FOOT}), leaving those that were found (the @samp{FOO} in 162 @samp{T} in @samp{FOOT}), leaving those that were found (the @samp{FOO} in
113 @samp{FOOT}). A second @kbd{C-g} at that point cancels the search 163 @samp{FOOT}). A second @kbd{C-g} at that point cancels the search
114 entirely, returning point to where it was when the search started. 164 entirely, returning point to where it was when the search started.
115 165
116 An upper-case letter in the search string makes the search
117 case-sensitive. If you delete the upper-case character from the search
118 string, it ceases to have this effect. @xref{Search Case}.
119
120 To search for a newline, type @kbd{C-j}. To search for another
121 control character, such as control-S or carriage return, you must quote
122 it by typing @kbd{C-q} first. This function of @kbd{C-q} is analogous
123 to its use for insertion (@pxref{Inserting Text}): it causes the
124 following character to be treated the way any ``ordinary'' character is
125 treated in the same context. You can also specify a character by its
126 octal code: enter @kbd{C-q} followed by a sequence of octal digits.
127
128 @cindex searching for non-@acronym{ASCII} characters
129 @cindex input method, during incremental search
130 To search for non-@acronym{ASCII} characters, you must use an input method
131 (@pxref{Input Methods}). If an input method is enabled in the
132 current buffer when you start the search, you can use it while you
133 type the search string also. Emacs indicates that by including the
134 input method mnemonic in its prompt, like this:
135
136 @example
137 I-search [@var{im}]:
138 @end example
139
140 @noindent
141 @findex isearch-toggle-input-method
142 @findex isearch-toggle-specified-input-method
143 where @var{im} is the mnemonic of the active input method. You can
144 toggle (enable or disable) the input method while you type the search
145 string with @kbd{C-\} (@code{isearch-toggle-input-method}). You can
146 turn on a certain (non-default) input method with @kbd{C-^}
147 (@code{isearch-toggle-specified-input-method}), which prompts for the
148 name of the input method. The input method you enable during
149 incremental search remains enabled in the current buffer afterwards.
150
151 If a search is failing and you ask to repeat it by typing another
152 @kbd{C-s}, it starts again from the beginning of the buffer.
153 Repeating a failing reverse search with @kbd{C-r} starts again from
154 the end. This is called @dfn{wrapping around}, and @samp{Wrapped}
155 appears in the search prompt once this has happened. If you keep on
156 going past the original starting point of the search, it changes to
157 @samp{Overwrapped}, which means that you are revisiting matches that
158 you have already seen.
159
160 @cindex quitting (in search) 166 @cindex quitting (in search)
161 The @kbd{C-g} ``quit'' character does special things during searches; 167 The @kbd{C-g} ``quit'' character does special things during searches;
162 just what it does depends on the status of the search. If the search has 168 just what it does depends on the status of the search. If the search has
163 found what you specified and is waiting for input, @kbd{C-g} cancels the 169 found what you specified and is waiting for input, @kbd{C-g} cancels the
164 entire search. The cursor moves back to where you started the search. If 170 entire search. The cursor moves back to where you started the search. If
167 has failed to find them---then the search string characters which have not 173 has failed to find them---then the search string characters which have not
168 been found are discarded from the search string. With them gone, the 174 been found are discarded from the search string. With them gone, the
169 search is now successful and waiting for more input, so a second @kbd{C-g} 175 search is now successful and waiting for more input, so a second @kbd{C-g}
170 will cancel the entire search. 176 will cancel the entire search.
171 177
172 You can change to searching backwards with @kbd{C-r}. If a search fails 178 @node Special Isearch
173 because the place you started was too late in the file, you should do this. 179 @subsection Special Input for Incremental Search
174 Repeated @kbd{C-r} keeps looking for more occurrences backwards. A 180
175 @kbd{C-s} starts going forwards again. @kbd{C-r} in a search can be canceled 181 An upper-case letter in the search string makes the search
176 with @key{DEL}. 182 case-sensitive. If you delete the upper-case character from the search
177 183 string, it ceases to have this effect. @xref{Search Case}.
178 @kindex C-r 184
179 @findex isearch-backward 185 To search for a newline, type @kbd{C-j}. To search for another
180 If you know initially that you want to search backwards, you can use 186 control character, such as control-S or carriage return, you must quote
181 @kbd{C-r} instead of @kbd{C-s} to start the search, because @kbd{C-r} as 187 it by typing @kbd{C-q} first. This function of @kbd{C-q} is analogous
182 a key runs a command (@code{isearch-backward}) to search backward. A 188 to its use for insertion (@pxref{Inserting Text}): it causes the
183 backward search finds matches that are entirely before the starting 189 following character to be treated the way any ``ordinary'' character is
184 point, just as a forward search finds matches that begin after it. 190 treated in the same context. You can also specify a character by its
191 octal code: enter @kbd{C-q} followed by a sequence of octal digits.
192
193 @kbd{M-%} typed in incremental search invokes @code{query-replace}
194 or @code{query-replace-regexp} (depending on search mode) with the
195 current search string used as the string to replace. @xref{Query
196 Replace}.
197
198 Entering @key{RET} when the search string is empty launches
199 nonincremental search (@pxref{Nonincremental Search}).
200
201 @vindex isearch-mode-map
202 To customize the special characters that incremental search understands,
203 alter their bindings in the keymap @code{isearch-mode-map}. For a list
204 of bindings, look at the documentation of @code{isearch-mode} with
205 @kbd{C-h f isearch-mode @key{RET}}.
206
207 @node Non-Ascii Isearch
208 @subsection Isearch for Non-@acronym{ASCII} Characters
209
210 @cindex searching for non-@acronym{ASCII} characters
211 @cindex input method, during incremental search
212
213 To enter non-@acronym{ASCII} characters in an incrementral search,
214 you must use an input method (@pxref{Input Methods}). If an input
215 method is enabled in the current buffer when you start the search, you
216 can use it while you type the search string also. Emacs indicates
217 that by including the input method mnemonic in its prompt, like this:
218
219 @example
220 I-search [@var{im}]:
221 @end example
222
223 @noindent
224 @findex isearch-toggle-input-method
225 @findex isearch-toggle-specified-input-method
226 where @var{im} is the mnemonic of the active input method. You can
227 toggle (enable or disable) the input method while you type the search
228 string with @kbd{C-\} (@code{isearch-toggle-input-method}). You can
229 turn on a certain (non-default) input method with @kbd{C-^}
230 (@code{isearch-toggle-specified-input-method}), which prompts for the
231 name of the input method. The input method you enable during
232 incremental search remains enabled in the current buffer afterwards.
233
234 @node Isearch Yank
235 @subsection Isearch Yanking
185 236
186 The characters @kbd{C-w} and @kbd{C-y} can be used in incremental 237 The characters @kbd{C-w} and @kbd{C-y} can be used in incremental
187 search to grab text from the buffer into the search string. This 238 search to grab text from the buffer into the search string. This
188 makes it convenient to search for another occurrence of text at point. 239 makes it convenient to search for another occurrence of text at point.
189 @kbd{C-w} copies the character or word after point as part of the 240 @kbd{C-w} copies the character or word after point as part of the
210 The character @kbd{M-y} copies text from the kill ring into the search 261 The character @kbd{M-y} copies text from the kill ring into the search
211 string. It uses the same text that @kbd{C-y} as a command would yank. 262 string. It uses the same text that @kbd{C-y} as a command would yank.
212 @kbd{Mouse-2} in the echo area does the same. 263 @kbd{Mouse-2} in the echo area does the same.
213 @xref{Yanking}. 264 @xref{Yanking}.
214 265
215 When you exit the incremental search, it sets the mark to where point 266 @node Highlight Isearch
216 @emph{was}, before the search. That is convenient for moving back 267 @subsection Lazy Search Highlighting
217 there. In Transient Mark mode, incremental search sets the mark without
218 activating it, and does so only if the mark is not already active.
219
220 @kbd{M-%} typed in incremental search invokes @code{query-replace}
221 or @code{query-replace-regexp} (depending on search mode) with the
222 current search string used as the string to replace. @xref{Query
223 Replace}.
224
225 @cindex lazy search highlighting 268 @cindex lazy search highlighting
226 @vindex isearch-lazy-highlight 269 @vindex isearch-lazy-highlight
270
227 When you pause for a little while during incremental search, it 271 When you pause for a little while during incremental search, it
228 highlights all other possible matches for the search string. This 272 highlights all other possible matches for the search string. This
229 makes it easier to anticipate where you can get to by typing @kbd{C-s} 273 makes it easier to anticipate where you can get to by typing @kbd{C-s}
230 or @kbd{C-r} to repeat the search. The short delay before highlighting 274 or @kbd{C-r} to repeat the search. The short delay before highlighting
231 other matches helps indicate which match is the current one. 275 other matches helps indicate which match is the current one.
236 You can control how this highlighting looks by customizing the faces 280 You can control how this highlighting looks by customizing the faces
237 @code{isearch} (used for the current match) and @code{lazy-highlight} 281 @code{isearch} (used for the current match) and @code{lazy-highlight}
238 (for all the other matches). The latter is also used for other matches 282 (for all the other matches). The latter is also used for other matches
239 inside @code{query-replace}. 283 inside @code{query-replace}.
240 284
241 @vindex isearch-mode-map 285 @node Isearch Scroll
242 To customize the special characters that incremental search understands,
243 alter their bindings in the keymap @code{isearch-mode-map}. For a list
244 of bindings, look at the documentation of @code{isearch-mode} with
245 @kbd{C-h f isearch-mode @key{RET}}.
246
247 @subsection Scrolling During Incremental Search 286 @subsection Scrolling During Incremental Search
248 287
249 Vertical scrolling during incremental search can be enabled by 288 Vertical scrolling during incremental search can be enabled by
250 setting the customizable variable @code{isearch-allow-scroll} to a 289 setting the customizable variable @code{isearch-allow-scroll} to a
251 non-@code{nil} value. 290 non-@code{nil} value.
266 (@code{split-window-vertically}) and @kbd{C-x ^} 305 (@code{split-window-vertically}) and @kbd{C-x ^}
267 (@code{enlarge-window}) which don't scroll the window, are 306 (@code{enlarge-window}) which don't scroll the window, are
268 nevertheless made available under this rubric, since they are likewise 307 nevertheless made available under this rubric, since they are likewise
269 handy during a search. 308 handy during a search.
270 309
271 For a list of commands which are configured as scrolling commands by 310 You can make other commands usable within an incremental search by
272 default and instructions on how thus to configure other commands, see 311 giving the command a non-@code{nil} @code{isearch-scroll} property.
273 @ref{Configuring Scrolling}. 312 This works for commands that don't permanently change point, the
274 313 buffer contents, the match data, the current buffer, or the selected
314 window and frame. The command must not delete the current window and
315 must not itself attempt an incremental search.
316
317 @node Slow Isearch
275 @subsection Slow Terminal Incremental Search 318 @subsection Slow Terminal Incremental Search
276 319
277 Incremental search on a slow terminal uses a modified style of display 320 Incremental search on a slow terminal uses a modified style of display
278 that is designed to take less time. Instead of redisplaying the buffer at 321 that is designed to take less time. Instead of redisplaying the buffer at
279 each place the search gets to, it creates a new single-line window and uses 322 each place the search gets to, it creates a new single-line window and uses
292 335
293 @vindex search-slow-window-lines 336 @vindex search-slow-window-lines
294 The number of lines to use in slow terminal search display is controlled 337 The number of lines to use in slow terminal search display is controlled
295 by the variable @code{search-slow-window-lines}. Its normal value is 1. 338 by the variable @code{search-slow-window-lines}. Its normal value is 1.
296 339
297 @node Nonincremental Search, Word Search, Incremental Search, Search 340 @node Nonincremental Search
298 @section Nonincremental Search 341 @section Nonincremental Search
299 @cindex nonincremental search 342 @cindex nonincremental search
300 343
301 Emacs also has conventional nonincremental search commands, which require 344 Emacs also has conventional nonincremental search commands, which require
302 you to type the entire search string before searching begins. 345 you to type the entire search string before searching begins.
332 commands may be bound to keys in the usual manner. The feature that you 375 commands may be bound to keys in the usual manner. The feature that you
333 can get to them via the incremental search commands exists for 376 can get to them via the incremental search commands exists for
334 historical reasons, and to avoid the need to find key sequences 377 historical reasons, and to avoid the need to find key sequences
335 for them. 378 for them.
336 379
337 @node Word Search, Regexp Search, Nonincremental Search, Search 380 @node Word Search
338 @section Word Search 381 @section Word Search
339 @cindex word search 382 @cindex word search
340 383
341 Word search searches for a sequence of words without regard to how the 384 Word search searches for a sequence of words without regard to how the
342 words are separated. More precisely, you type a string of many words, 385 words are separated. More precisely, you type a string of many words,
371 @code{word-search-forward} and @code{word-search-backward}. These 414 @code{word-search-forward} and @code{word-search-backward}. These
372 commands may be bound to keys in the usual manner. They are available 415 commands may be bound to keys in the usual manner. They are available
373 via the incremental search commands both for historical reasons and 416 via the incremental search commands both for historical reasons and
374 to avoid the need to find suitable key sequences for them. 417 to avoid the need to find suitable key sequences for them.
375 418
376 @node Regexp Search, Regexps, Word Search, Search 419 @node Regexp Search
377 @section Regular Expression Search 420 @section Regular Expression Search
378 @cindex regular expression 421 @cindex regular expression
379 @cindex regexp 422 @cindex regexp
380 423
381 A @dfn{regular expression} (@dfn{regexp}, for short) is a pattern 424 A @dfn{regular expression} (@dfn{regexp}, for short) is a pattern
382 that denotes a class of alternative strings to match, possibly 425 that denotes a class of alternative strings to match, possibly
383 infinitely many. GNU Emacs provides both incremental and 426 infinitely many. GNU Emacs provides both incremental and
384 nonincremental ways to search for a match for a regexp. 427 nonincremental ways to search for a match for a regexp. The syntax of
428 regular expressions is explained in the following section.
385 429
386 @kindex C-M-s 430 @kindex C-M-s
387 @findex isearch-forward-regexp 431 @findex isearch-forward-regexp
388 @kindex C-M-r 432 @kindex C-M-r
389 @findex isearch-backward-regexp 433 @findex isearch-backward-regexp
427 If you use the incremental regexp search commands with a prefix 471 If you use the incremental regexp search commands with a prefix
428 argument, they perform ordinary string search, like 472 argument, they perform ordinary string search, like
429 @code{isearch-forward} and @code{isearch-backward}. @xref{Incremental 473 @code{isearch-forward} and @code{isearch-backward}. @xref{Incremental
430 Search}. 474 Search}.
431 475
432 @node Regexps, Search Case, Regexp Search, Search 476 @node Regexps
433 @section Syntax of Regular Expressions 477 @section Syntax of Regular Expressions
434 @cindex syntax of regexps 478 @cindex syntax of regexps
435 479
436 This manual describes regular expression features that users 480 This manual describes regular expression features that users
437 typically want to use. There are additional features that are 481 typically want to use. There are additional features that are
828 verify even very complex regexps. (On displays that don't support 872 verify even very complex regexps. (On displays that don't support
829 colors, Emacs blinks the cursor around the matched text, as it does 873 colors, Emacs blinks the cursor around the matched text, as it does
830 for matching parens.) 874 for matching parens.)
831 @end ignore 875 @end ignore
832 876
833 @node Search Case, Configuring Scrolling, Regexps, Search 877 @node Search Case
834 @section Searching and Case 878 @section Searching and Case
835 879
836 Incremental searches in Emacs normally ignore the case of the text 880 Incremental searches in Emacs normally ignore the case of the text
837 they are searching through, if you specify the text in lower case. 881 they are searching through, if you specify the text in lower case.
838 Thus, if you specify searching for @samp{foo}, then @samp{Foo} and 882 Thus, if you specify searching for @samp{foo}, then @samp{Foo} and
850 sensitivity of that search. The effect does not extend beyond the 894 sensitivity of that search. The effect does not extend beyond the
851 current incremental search to the next one, but it does override the 895 current incremental search to the next one, but it does override the
852 effect of including an upper-case letter in the current search. 896 effect of including an upper-case letter in the current search.
853 897
854 @vindex case-fold-search 898 @vindex case-fold-search
899 @vindex default-case-fold-search
855 If you set the variable @code{case-fold-search} to @code{nil}, then 900 If you set the variable @code{case-fold-search} to @code{nil}, then
856 all letters must match exactly, including case. This is a per-buffer 901 all letters must match exactly, including case. This is a per-buffer
857 variable; altering the variable affects only the current buffer, but 902 variable; altering the variable affects only the current buffer, but
858 there is a default value which you can change as well. @xref{Locals}. 903 there is a default value in @code{default-case-fold-search} that you
859 This variable applies to nonincremental searches also, including those 904 can also set. @xref{Locals}. This variable applies to nonincremental
860 performed by the replace commands (@pxref{Replace}) and the minibuffer 905 searches also, including those performed by the replace commands
861 history matching commands (@pxref{Minibuffer History}). 906 (@pxref{Replace}) and the minibuffer history matching commands
862 907 (@pxref{Minibuffer History}).
863 @node Configuring Scrolling, Replace, Search Case, Search 908
864 @section Configuring Scrolling 909 @node Replace
865 @cindex scrolling in incremental search
866 @vindex isearch-allow-scroll
867
868 Scrolling, etc., during incremental search is enabled by setting the
869 customizable variable @code{isearch-allow-scroll} to a non-@code{nil} value.
870
871 @c See Subject: Info file: How do I get an itemized list without blank lines?
872 @c Date: Sat, 12 Apr 2003 09:45:31 +0000 in gnu.emacs.help
873 @subsection Standard scrolling commands
874 Here is the list of commands which are configured by default to be
875 ``scrolling'' commands in an incremental search, together with their
876 usual bindings:
877 @subsubsection Commands which scroll the window:
878 @table @asis
879 @item @code{scroll-bar-toolkit-scroll} (@kbd{@key{vertical-scroll-bar}@key{mouse-1}} in X-Windows)
880 @itemx @code{mac-handle-scroll-bar-event} (@kbd{@key{vertical-scroll-bar}@key{mouse-1}} on a Mac)
881 @itemx @code{w32-handle-scroll-bar-event} (@kbd{@key{vertical-scroll-bar}@key{mouse-1}} in MS-Windows)
882 @item @code{recenter} (@kbd{C-l}) @xref{Scrolling}.
883 @itemx @code{reposition-window} (@kbd{C-M-l}) @xref{Scrolling}.
884 @itemx @code{scroll-up} (@kbd{@key{NEXT}}) @xref{Scrolling}.
885 @itemx @code{scroll-down} (@kbd{@key{PRIOR}}) @xref{Scrolling}.
886 @end table
887
888 @subsubsection Commands which act on the other window:
889 @table @asis
890 @item @code{list-buffers} (@kbd{C-x C-b}) @xref{List Buffers}.
891 @itemx @code{scroll-other-window} (@kbd{C-M-v}) @xref{Other Window}.
892 @itemx @code{scroll-other-window-down} (@kbd{C-M-S-v}) @xref{Other Window}.
893 @itemx @code{beginning-of-buffer-other-window} (@kbd{M-@key{home}})
894 @itemx @code{end-of-buffer-other-window} (@kbd{M-@key{end}})
895 @end table
896
897 @subsubsection Commands which change the window layout:
898 @table @asis
899 @item @code{delete-other-windows} (@kbd{C-x 1}) @xref{Change Window}.
900 @itemx @code{balance-windows} (@kbd{C-x +}) @xref{Change Window}.
901 @itemx @code{split-window-vertically} (@kbd{C-x 2}) @xref{Split Window}.
902 @itemx @code{enlarge-window} (@kbd{C-x ^}) @xref{Change Window}.
903 @end table
904
905 @subsection Configuring other commands as scrolling commands
906 To do this, set a command's isearch-scroll property to the value t.
907 For example:
908
909 @example
910 @code{(put 'my-command 'isearch-scroll t)}
911 @end example
912
913 You should only thus configure commands which are ``safe'': i.e., they
914 won't leave emacs in an inconsistent state when executed within a
915 search---that is to say, the following things may be changed by a
916 command only temporarily, and must be restored before the command
917 finishes:
918
919 @enumerate
920 @item
921 Point.
922 @item
923 The buffer contents.
924 @item
925 The selected window and selected frame.
926 @item
927 The current match-data. @xref{Match Data,,, elisp, The Emacs Lisp
928 Reference Manual}.
929 @end enumerate
930
931 Additionally, the command must not delete the current window and must
932 not itself attempt an incremental search. It may, however, change the
933 window's size, or create or delete other windows and frames.
934
935 Note that an attempt by a command to scroll the text
936 @emph{horizontally} won't work, although it will do no harm---any such
937 scrolling will be overridden and nullified by the display code.
938
939 @node Replace, Other Repeating Search, Configuring Scrolling, Search
940 @section Replacement Commands 910 @section Replacement Commands
941 @cindex replacement 911 @cindex replacement
942 @cindex search-and-replace commands 912 @cindex search-and-replace commands
943 @cindex string substitution 913 @cindex string substitution
944 @cindex global substitution 914 @cindex global substitution
965 @end menu 935 @end menu
966 936
967 @node Unconditional Replace, Regexp Replace, Replace, Replace 937 @node Unconditional Replace, Regexp Replace, Replace, Replace
968 @subsection Unconditional Replacement 938 @subsection Unconditional Replacement
969 @findex replace-string 939 @findex replace-string
970 @findex replace-regexp
971 940
972 @table @kbd 941 @table @kbd
973 @item M-x replace-string @key{RET} @var{string} @key{RET} @var{newstring} @key{RET} 942 @item M-x replace-string @key{RET} @var{string} @key{RET} @var{newstring} @key{RET}
974 Replace every occurrence of @var{string} with @var{newstring}. 943 Replace every occurrence of @var{string} with @var{newstring}.
975 @item M-x replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET}
976 Replace every match for @var{regexp} with @var{newstring}.
977 @end table 944 @end table
978 945
979 To replace every instance of @samp{foo} after point with @samp{bar}, 946 To replace every instance of @samp{foo} after point with @samp{bar},
980 use the command @kbd{M-x replace-string} with the two arguments 947 use the command @kbd{M-x replace-string} with the two arguments
981 @samp{foo} and @samp{bar}. Replacement happens only in the text after 948 @samp{foo} and @samp{bar}. Replacement happens only in the text after
1006 This works provided the string @samp{@@TEMP@@} does not appear 973 This works provided the string @samp{@@TEMP@@} does not appear
1007 in your text. 974 in your text.
1008 975
1009 @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace 976 @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace
1010 @subsection Regexp Replacement 977 @subsection Regexp Replacement
978 @findex replace-regexp
1011 979
1012 The @kbd{M-x replace-string} command replaces exact matches for a 980 The @kbd{M-x replace-string} command replaces exact matches for a
1013 single string. The similar command @kbd{M-x replace-regexp} replaces 981 single string. The similar command @kbd{M-x replace-regexp} replaces
1014 any match for a specified pattern. 982 any match for a specified pattern.
983
984 @table @kbd
985 @item M-x replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET}
986 Replace every match for @var{regexp} with @var{newstring}.
987 @end table
1015 988
1016 In @code{replace-regexp}, the @var{newstring} need not be constant: 989 In @code{replace-regexp}, the @var{newstring} need not be constant:
1017 it can refer to all or part of what is matched by the @var{regexp}. 990 it can refer to all or part of what is matched by the @var{regexp}.
1018 @samp{\&} in @var{newstring} stands for the entire match being 991 @samp{\&} in @var{newstring} stands for the entire match being
1019 replaced. @samp{\@var{d}} in @var{newstring}, where @var{d} is a 992 replaced. @samp{\@var{d}} in @var{newstring}, where @var{d} is a
1256 ESC}. 1229 ESC}.
1257 1230
1258 See also @ref{Transforming File Names}, for Dired commands to rename, 1231 See also @ref{Transforming File Names}, for Dired commands to rename,
1259 copy, or link files by replacing regexp matches in file names. 1232 copy, or link files by replacing regexp matches in file names.
1260 1233
1261 @node Other Repeating Search,, Replace, Search 1234 @node Other Repeating Search
1262 @section Other Search-and-Loop Commands 1235 @section Other Search-and-Loop Commands
1263 1236
1264 Here are some other commands that find matches for a regular 1237 Here are some other commands that find matches for a regular
1265 expression. They all ignore case in matching, if the pattern contains 1238 expression. They all ignore case in matching, if the pattern contains
1266 no upper-case letters and @code{case-fold-search} is non-@code{nil}. 1239 no upper-case letters and @code{case-fold-search} is non-@code{nil}.