Next: , Previous: , Up: Search   [Contents][Index]

15.10 Replacement Commands

Emacs provides several commands for performing search-and-replace operations. In addition to the simple M-x replace-string command, there is M-% (query-replace), which presents each occurrence of the pattern and asks you whether to replace it.

The replace commands normally operate on the text from point to the end of the buffer. When the region is active, they operate on it instead (see Mark). The basic replace commands replace one search string (or regexp) with one replacement string. It is possible to perform several replacements in parallel, using the command expand-region-abbrevs (see Expanding Abbrevs).

Unlike incremental search, the replacement commands do not use lax space matching (see Special Isearch) by default. To enable lax space matching for replacement, change the variable replace-lax-whitespace to t. (This only affects how Emacs finds the text to replace, not the replacement text.)