comparison man/search.texi @ 68515:feb2110d1e96

Minor clarifications. (Isearch Scroll): Simplify. (Other Repeating Search): Document multi-occur-in-matching-buffers.
author Richard M. Stallman <rms@gnu.org>
date Tue, 31 Jan 2006 18:30:11 +0000
parents 8430a6e62d6c
children dc2d5a6655a3 7432ca837c8d
comparison
equal deleted inserted replaced
68514:11e04df4c09e 68515:feb2110d1e96
39 shows you where the string (as you have typed it so far) would be 39 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 40 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 41 want, you can stop. Depending on what you plan to do next, you may or
42 may not need to terminate the search explicitly with @key{RET}. 42 may not need to terminate the search explicitly with @key{RET}.
43 43
44 @c WideCommands
45 @table @kbd 44 @table @kbd
46 @item C-s 45 @item C-s
47 Incremental search forward (@code{isearch-forward}). 46 Incremental search forward (@code{isearch-forward}).
48 @item C-r 47 @item C-r
49 Incremental search backward (@code{isearch-backward}). 48 Incremental search backward (@code{isearch-backward}).
71 @kbd{C-s} starts a forward incremental search. It reads characters 70 @kbd{C-s} starts a forward incremental search. It reads characters
72 from the keyboard, and moves point past the next occurrence of those 71 from the keyboard, and moves point past the next occurrence of those
73 characters. If you type @kbd{C-s} and then @kbd{F}, that puts the 72 characters. If you type @kbd{C-s} and then @kbd{F}, that puts the
74 cursor after the first @samp{F} (the first following the starting point, since 73 cursor after the first @samp{F} (the first following the starting point, since
75 this is a forward search). Then if you type an @kbd{O}, you will see 74 this is a forward search). Then if you type an @kbd{O}, you will see
76 the cursor move just after the first @samp{FO} (the @samp{F} in that 75 the cursor move to just after the first @samp{FO} (the @samp{F} in that
77 @samp{FO} may or may not be the first @samp{F}). After another 76 @samp{FO} may or may not be the first @samp{F}). After another
78 @kbd{O}, the cursor moves after the first @samp{FOO} after the place 77 @kbd{O}, the cursor moves to just after the first @samp{FOO} after the place
79 where you started the search. At each step, the buffer text that 78 where you started the search. At each step, the buffer text that
80 matches the search string is highlighted, if the terminal can do that; 79 matches the search string is highlighted, if the terminal can do that;
81 the current search string is always displayed in the echo area. 80 the current search string is always displayed in the echo area.
82 81
83 If you make a mistake in typing the search string, you can cancel 82 If you make a mistake in typing the search string, you can cancel
133 in the minibuffer, where you can edit it. To edit the current search 132 in the minibuffer, where you can edit it. To edit the current search
134 string in the minibuffer without replacing it with items from the 133 string in the minibuffer without replacing it with items from the
135 search ring, type @kbd{M-e}. Type @kbd{C-s} or @kbd{C-r} 134 search ring, type @kbd{M-e}. Type @kbd{C-s} or @kbd{C-r}
136 to terminate editing the string and search for it. 135 to terminate editing the string and search for it.
137 136
138 You can change to searching backwards with @kbd{C-r}. If a search fails 137 You can change to searching backwards with @kbd{C-r}. For instance,
139 because the place you started was too late in the file, you should do this. 138 if you are searching forward but you realize you were looking for
140 Repeated @kbd{C-r} keeps looking for more occurrences backwards. A 139 something above the starting point, you can do this. Repeated
141 @kbd{C-s} starts going forwards again. @kbd{C-r} in a search can be canceled 140 @kbd{C-r} keeps looking for more occurrences backwards. A @kbd{C-s}
141 starts going forwards again. @kbd{C-r} in a search can be canceled
142 with @key{DEL}. 142 with @key{DEL}.
143 143
144 @kindex C-r 144 @kindex C-r
145 @findex isearch-backward 145 @findex isearch-backward
146 If you know initially that you want to search backwards, you can use 146 If you know initially that you want to search backwards, you can use
147 @kbd{C-r} instead of @kbd{C-s} to start the search, because @kbd{C-r} as 147 @kbd{C-r} instead of @kbd{C-s} to start the search, because @kbd{C-r}
148 a key runs a command (@code{isearch-backward}) to search backward. A 148 as a key runs a command (@code{isearch-backward}) to search backward.
149 backward search finds matches that are entirely before the starting 149 A backward search finds matches that end before the starting point,
150 point, just as a forward search finds matches that begin after it. 150 just as a forward search finds matches that begin after it.
151 151
152 @node Error in Isearch 152 @node Error in Isearch
153 @subsection Errors in Incremental Search 153 @subsection Errors in Incremental Search
154 154
155 If your string is not found at all, the echo area says @samp{Failing 155 If your string is not found at all, the echo area says @samp{Failing
279 @code{isearch-lazy-highlight} to @code{nil}. 279 @code{isearch-lazy-highlight} to @code{nil}.
280 280
281 @cindex faces for highlighting search matches 281 @cindex faces for highlighting search matches
282 You can control how this highlighting looks by customizing the faces 282 You can control how this highlighting looks by customizing the faces
283 @code{isearch} (used for the current match) and @code{lazy-highlight} 283 @code{isearch} (used for the current match) and @code{lazy-highlight}
284 (for all the other matches). The latter is also used for other matches 284 (for all the other matches).
285 inside @code{query-replace}.
286 285
287 @node Isearch Scroll 286 @node Isearch Scroll
288 @subsection Scrolling During Incremental Search 287 @subsection Scrolling During Incremental Search
289 288
290 Vertical scrolling during incremental search can be enabled by 289 You can enable the use of vertical scrolling during incremental
291 setting the customizable variable @code{isearch-allow-scroll} to a 290 search (without exiting the search) by setting the customizable
292 non-@code{nil} value. 291 variable @code{isearch-allow-scroll} to a non-@code{nil} value. This
293 292 applies to using the vertical scroll-bar and to certain keyboard
294 You can then use the vertical scroll-bar or certain keyboard
295 commands such as @kbd{@key{PRIOR}} (@code{scroll-down}), 293 commands such as @kbd{@key{PRIOR}} (@code{scroll-down}),
296 @kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter}) 294 @kbd{@key{NEXT}} (@code{scroll-up}) and @kbd{C-l} (@code{recenter}).
297 within the search, thus letting you see more of the text near the 295 You must run these commands via their key sequences to stay in the
298 current match. You must run these commands via their key sequences to 296 search---typing @kbd{M-x} will terminate the search. You can give
299 stay in the search---typing M-x @var{command-name} will always 297 prefix arguments to these commands in the usual way.
300 terminate a search. 298
301 299 This feature won't let you scroll the current match out of visibility,
302 You can give prefix arguments to these commands in the usual way. 300 however.
303 The current match cannot be scrolled out of the window---this is 301
304 intentional. 302 The feature also affects some other commands, such as @kbd{C-x 2}
305
306 Several other commands, such as @kbd{C-x 2}
307 (@code{split-window-vertically}) and @kbd{C-x ^} 303 (@code{split-window-vertically}) and @kbd{C-x ^}
308 (@code{enlarge-window}) which don't scroll the window, are 304 (@code{enlarge-window}) which don't exactly scroll but do affect where
309 nevertheless made available under this rubric, since they are likewise 305 the text appears on the screen. In general, it applies to any command
310 handy during a search. 306 whose name has a non-@code{nil} @code{isearch-scroll} property. So you
311 307 can control which commands are affected by changing these properties.
312 You can make other commands usable within an incremental search by 308
313 giving the command a non-@code{nil} @code{isearch-scroll} property. 309 For example, to make @kbd{C-h l} usable within an incremental search
314 For example, to make @kbd{C-h l} usable within an incremental search
315 in all future Emacs sessions, use @kbd{C-h c} to find what command it 310 in all future Emacs sessions, use @kbd{C-h c} to find what command it
316 runs. (You type @kbd{C-h c C-h l}; it says @code{view-lossage}.) Then 311 runs. (You type @kbd{C-h c C-h l}; it says @code{view-lossage}.)
317 you can put the following line in your @file{.emacs} file (@pxref{Init File}): 312 Then you can put the following line in your @file{.emacs} file
313 (@pxref{Init File}):
318 314
319 @example 315 @example
320 (put 'view-lossage 'isearch-scroll t) 316 (put 'view-lossage 'isearch-scroll t)
321 @end example 317 @end example
322 318
323 @noindent 319 @noindent
324 This works for commands that don't permanently change point, the 320 This feature can be applied to any command that doesn't permanently
325 buffer contents, the match data, the current buffer, or the selected 321 change point, the buffer contents, the match data, the current buffer,
326 window and frame. The command must not delete the current window and 322 or the selected window and frame. The command must not itself attempt
327 must not itself attempt an incremental search. 323 an incremental search.
328 324
329 @node Slow Isearch 325 @node Slow Isearch
330 @subsection Slow Terminal Incremental Search 326 @subsection Slow Terminal Incremental Search
331 327
332 Incremental search on a slow terminal uses a modified style of display 328 Incremental search on a slow terminal uses a modified style of display
385 @findex search-backward 381 @findex search-backward
386 Forward and backward nonincremental searches are implemented by the 382 Forward and backward nonincremental searches are implemented by the
387 commands @code{search-forward} and @code{search-backward}. These 383 commands @code{search-forward} and @code{search-backward}. These
388 commands may be bound to keys in the usual manner. The feature that you 384 commands may be bound to keys in the usual manner. The feature that you
389 can get to them via the incremental search commands exists for 385 can get to them via the incremental search commands exists for
390 historical reasons, and to avoid the need to find key sequences 386 historical reasons, and to avoid the need to find separate key sequences
391 for them. 387 for them.
392 388
393 @node Word Search 389 @node Word Search
394 @section Word Search 390 @section Word Search
395 @cindex word search 391 @cindex word search
425 @findex word-search-backward 421 @findex word-search-backward
426 Forward and backward word searches are implemented by the commands 422 Forward and backward word searches are implemented by the commands
427 @code{word-search-forward} and @code{word-search-backward}. These 423 @code{word-search-forward} and @code{word-search-backward}. These
428 commands may be bound to keys in the usual manner. They are available 424 commands may be bound to keys in the usual manner. They are available
429 via the incremental search commands both for historical reasons and 425 via the incremental search commands both for historical reasons and
430 to avoid the need to find suitable key sequences for them. 426 to avoid the need to find separate key sequences for them.
431 427
432 @node Regexp Search 428 @node Regexp Search
433 @section Regular Expression Search 429 @section Regular Expression Search
434 @cindex regular expression 430 @cindex regular expression
435 @cindex regexp 431 @cindex regexp
466 462
467 @vindex search-whitespace-regexp 463 @vindex search-whitespace-regexp
468 If you type @key{SPC} in incremental regexp search, it matches any 464 If you type @key{SPC} in incremental regexp search, it matches any
469 sequence of whitespace characters, including newlines. If you want to 465 sequence of whitespace characters, including newlines. If you want to
470 match just a space, type @kbd{C-q @key{SPC}}. You can control what a 466 match just a space, type @kbd{C-q @key{SPC}}. You can control what a
471 bare spece matches by setting the variable 467 bare space matches by setting the variable
472 @code{search-whitespace-regexp} to the desired regexp. 468 @code{search-whitespace-regexp} to the desired regexp.
473 469
474 Note that adding characters to the regexp in an incremental regexp 470 In some cases, adding characters to the regexp in an incremental regexp
475 search can make the cursor move back and start again. For example, if 471 search can make the cursor move back and start again. For example, if
476 you have searched for @samp{foo} and you add @samp{\|bar}, the cursor 472 you have searched for @samp{foo} and you add @samp{\|bar}, the cursor
477 backs up in case the first @samp{bar} precedes the first @samp{foo}. 473 backs up in case the first @samp{bar} precedes the first @samp{foo}.
478 474
479 @findex re-search-forward 475 @findex re-search-forward
930 of the pattern and asks you whether to replace it. 926 of the pattern and asks you whether to replace it.
931 927
932 The replace commands normally operate on the text from point to the 928 The replace commands normally operate on the text from point to the
933 end of the buffer; however, in Transient Mark mode (@pxref{Transient 929 end of the buffer; however, in Transient Mark mode (@pxref{Transient
934 Mark}), when the mark is active, they operate on the region. The 930 Mark}), when the mark is active, they operate on the region. The
935 replace commands all replace one string (or regexp) with one 931 basic replace commands replace one string (or regexp) with one
936 replacement string. It is possible to perform several replacements in 932 replacement string. It is possible to perform several replacements in
937 parallel using the command @code{expand-region-abbrevs} 933 parallel using the command @code{expand-region-abbrevs}
938 (@pxref{Expanding Abbrevs}). 934 (@pxref{Expanding Abbrevs}).
939 935
940 @menu 936 @menu
1244 Mark mode. 1240 Mark mode.
1245 1241
1246 @findex list-matching-lines 1242 @findex list-matching-lines
1247 @findex occur 1243 @findex occur
1248 @findex multi-occur 1244 @findex multi-occur
1249 @findex multi-occur-by-filename-regexp 1245 @findex multi-occur-in-matching-buffers
1250 @findex how-many 1246 @findex how-many
1251 @findex delete-non-matching-lines 1247 @findex delete-non-matching-lines
1252 @findex delete-matching-lines 1248 @findex delete-matching-lines
1253 @findex flush-lines 1249 @findex flush-lines
1254 @findex keep-lines 1250 @findex keep-lines
1271 point there and type @key{RET}; this switches to the buffer that was 1267 point there and type @key{RET}; this switches to the buffer that was
1272 searched and moves point to the original of the chosen occurrence. 1268 searched and moves point to the original of the chosen occurrence.
1273 @kbd{o} and @kbd{C-o} display the match in another window; @kbd{C-o} 1269 @kbd{o} and @kbd{C-o} display the match in another window; @kbd{C-o}
1274 does not select it. 1270 does not select it.
1275 1271
1276 Occur mode supports the @code{next-error} functionality described in 1272 After using @kbd{M-x occur}, you can use @code{next-error} to visit
1277 @ref{Compilation Mode}. 1273 the occurrences found, one by one. @ref{Compilation Mode}.
1278 1274
1279 @item M-x list-matching-lines 1275 @item M-x list-matching-lines
1280 Synonym for @kbd{M-x occur}. 1276 Synonym for @kbd{M-x occur}.
1281 1277
1282 @item M-x multi-occur @key{RET} @var{buffers} @key{RET} @var{regexp} @key{RET} 1278 @item M-x multi-occur @key{RET} @var{buffers} @key{RET} @var{regexp} @key{RET}
1283 This function is just like @code{occur}, except it is able to search 1279 This function is just like @code{occur}, except it is able to search
1284 through multiple buffers. 1280 through multiple buffers. It asks you to specify the buffer names one by one.
1285 1281
1286 @item M-x multi-occur-by-filename-regexp @key{RET} @var{bufregexp} @key{RET} @var{regexp} @key{RET} 1282 @item M-x multi-occur-in-matching-buffers @key{RET} @var{bufregexp} @key{RET} @var{regexp} @key{RET}
1287 This function is similar to @code{multi-occur}, except the buffers to 1283 This function is similar to @code{multi-occur}, except the buffers to
1288 search are specified by a regexp on their filename. 1284 search are specified by a regular expression that matches visited
1285 filenames. With a prefix argument, it uses the regular expression to match
1286 buffer names instead.
1289 1287
1290 @item M-x how-many @key{RET} @var{regexp} @key{RET} 1288 @item M-x how-many @key{RET} @var{regexp} @key{RET}
1291 Print the number of matches for @var{regexp} that exist in the buffer 1289 Print the number of matches for @var{regexp} that exist in the buffer
1292 after point. In Transient Mark mode, if the region is active, the 1290 after point. In Transient Mark mode, if the region is active, the
1293 command operates on the region instead. 1291 command operates on the region instead.