Edit the previous search string in emacs query-replace?

emacs

Solution

Yah, try M-p, something like this sequence

M-% M-p [return] M-p [DEL] C [return]

Problem

When using query-replace (with or without regexp) in emacs, the previous query-replace pair is remembered and suggested as default the next time query-replace is invoked. But I would like to be able to edit this default replacement to something similar without having to type the entire new variant. Like this: in a section of a long document I do a query-replace ``` M-% antidisestablishmentarianism-A [return] antidisestablismentarianism-B ``` later on in the same document I want to do ``` M-% antidisestablishmentarianism-A [return] antidisestablismentarianism-C ``` The command M-% on its own gives ``` Query-replace (default antidisestablishmentarianism-A -> antidisestablismentarianism-B): ``` Is there some magic key combination which makes it possible to change that final "B" to a "C" without retyping?

Original source