This function is the guts of
query-replaceand related commands. It searches for occurrences of from-string and replaces some or all of them. If query-flag isnil, it replaces all occurrences; otherwise, it asks the user what to do about each one.If regexp-flag is non-
nil, then from-string is considered a regular expression; otherwise, it must match literally. If delimited-flag is non-nil, then only replacements surrounded by word boundaries are considered.The argument replacements specifies what to replace occurrences with. If it is a string, that string is used. It can also be a list of strings, to be used in cyclic order.
If repeat-count is non-
nil, it should be an integer. Then it specifies how many times to use each of the strings in the replacements list before advancing cyclicly to the next one.Normally, the keymap
query-replace-mapdefines the possible user responses for queries. The argument map, if non-nil, is a keymap to use instead ofquery-replace-map.
This variable holds a special keymap that defines the valid user responses for
query-replaceand related functions, as well asy-or-n-pandmap-y-or-n-p. It is unusual in two ways:
- The “key bindings” are not commands, just symbols that are meaningful to the functions that use this map.
- Prefix keys are not supported; each key binding must be for a single event key sequence. This is because the functions don't use read key sequence to get the input; instead, they read a single event and look it up “by hand.”
Here are the meaningful “bindings” for query-replace-map.
Several of them are meaningful only for query-replace and
friends.
actskipexitact-and-exitact-and-showautomaticbackupeditdelete-and-editrecenterquity-or-n-p and related functions
use this answer.
help