Next: , Previous: Error in Isearch, Up: Incremental Search

15.1.4 Special Input for Incremental Search

Some of the characters you type during incremental search have special effects.

By default, incremental search performs lax space matching: each space, or sequence of spaces, matches any sequence of one or more spaces in the text. Hence, ‘foo bar’ matches ‘foo bar’, ‘foo bar’, ‘foo bar’, and so on (but not ‘foobar’). More precisely, Emacs matches each sequence of space characters in the search string to a regular expression specified by the variable search-whitespace-regexp. For example, set it to ‘"[[:space:]\n]+"’ to make spaces match sequences of newlines as well as spaces. To toggle lax space matching, type M-s SPC (isearch-toggle-lax-whitespace). To disable this feature entirely, change search-whitespace-regexp to nil; then each space in the search string matches exactly one space

If the search string you entered contains only lower-case letters, the search is case-insensitive; as long as an upper-case letter exists in the search string, the search becomes case-sensitive. If you delete the upper-case character from the search string, it ceases to have this effect. See Search Case.

To search for a newline character, type C-j.

To search for other control characters, such as <control-S>, quote it by typing C-q first (see Inserting Text). To search for non-ASCII characters, you can either use C-q and enter its octal code, or use an input method (see Input Methods). If an input method is enabled in the current buffer when you start the search, you can use it in the search string also. While typing the search string, you can toggle the input method with the command C-\ (isearch-toggle-input-method). You can also turn on a non-default input method with C-^ (isearch-toggle-specified-input-method), which prompts for the name of the input method. When an input method is active during incremental search, the search prompt includes the input method mnemonic, like this:

     I-search [im]:

where im is the mnemonic of the active input method. Any input method you enable during incremental search remains enabled in the current buffer afterwards.

Typing M-% in incremental search invokes query-replace or query-replace-regexp (depending on search mode) with the current search string used as the string to replace. See Query Replace.

Typing M-<TAB> in incremental search invokes isearch-complete, which attempts to complete the search string using the search ring as a list of completion alternatives. See Completion. In many operating systems, the M-<TAB> key sequence is captured by the window manager; you then need to rebind isearch-complete to another key sequence if you want to use it (see Rebinding).

When incremental search is active, you can type C-h C-h to access interactive help options, including a list of special key bindings. These key bindings are part of the keymap isearch-mode-map (see Keymaps).