the case: Let's say I did a query-replace is foo1 with foo2, and now I want to query-replace foo2 with foo1.

In earlier versions of emacs (emacs 24, and every other version I remember), each previous entry into query-replace could be accessed via the up-arrow:

I used to go ESC-% (query-replace), up-arrow ** x1, it then shows ("foo2"), RETURN, then up-arrow x3 ("foo1"), RETURN.

In my new Emacs (emacs 25), up-arrow gives me the entire previous query-replace ("foo1 -> foo2"), instead of each field separately.

So I've got to do a rather convoluted edit which involves:

  • putting either foo1 or foo2 onto the clipboard. e.g. put foo1 onto clip board (which involves many keystrokes if foo1 is long and complicated)
  • 3 x delete (to remove the arrow and spaces),
  • RETURN ctrl-Y, RETURN.

I've no idea why emacs 25 "improved" `query-replace up-arrow like that, but I find it a pain.

Is there any way to get the old, simpler, query-replace up-arrow functionality?

  • Note that you can also (still) use C-x ESC ESC to repeat the command, editing the inputs if needed.
    – Drew
    Sep 14, 2018 at 1:21
  • I've found this page endlessparentheses.com/… which points out that the arrow is "intangible" so I can switch the 2 fields around, so a simple ESC-T switches their places if they are single words, which is neat. But I see no simple way to do it for more complicated strings, as far as I can see.
    – Peter B
    Sep 14, 2018 at 1:30
  • But, I will grant that this ESC-T is suitable about 90% of the time, so mostly solves my desire to do simple edits quickly.
    – Peter B
    Sep 14, 2018 at 1:34

1 Answer 1


If you upgrade to 26.1 you can set query-replace-from-to-separator to nil

25.1 NEWS:

*** 'query-replace' history is enhanced.
When 'query-replace' reads the FROM string from the minibuffer, typing 'M-p' will now show previous replacements as "FROM SEP TO", where FROM and TO are the original text and its replacement, and SEP is an arrow string defined by the new variable 'query-replace-from-to-separator'. To select a prior replacement, type 'M-p' until the desired replacement appears in the minibuffer, and then exit the minibuffer by typing RET.

26.1 NEWS:

** Customizable variable 'query-replace-from-to-separator' now doesn't propertize the string value of the separator. Instead, text properties are added by 'query-replace-read-from'. Additionally, the new nil value restores pre-24.5 behavior of not providing replacement pairs via the history.

Edit: Cursory testing in 25.3 suggests that you can probably use the definition of query-replace-read-from from 26.1 to get the same behaviour. Just copy it to your init file.

If you copy the definition of query-replace-from-to-separator as well, then you'll also get the customize interface with the "Disabled" option; but you can use the following regardless:

(setq query-replace-from-to-separator nil)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.