3

Assume that I perform a query-replace in a document. When the process is finished, is there a simple way (1) to return to the original place where query-replace was started? (2) to return to the first place where a replacement was done?

2

(1) to return to the original place where query-replace was started?

C-uC-SPC

n.b. This works in many situations, as commands which are liable to move point by some arbitrary distance commonly push to the mark ring first, for this purpose.

(2) to return to the first place where a replacement was done?

I can't think of a standard way to do that.

You can always use diff-buffer-with-file or ediff-current-file to find out what changes you've made since you last saved the file.

  • Thanks, is there an elisp equivalent of C-u C-SPC? – Name Jun 7 '17 at 13:58
  • @Name M-x describe-key RET C-SPC (or C-h k C-SPC) reports that the key is bound to the command set-mark-command. – Basil Jun 7 '17 at 14:26
  • Basil is correct, but a call to (pop-to-mark-command) is what is ultimately happening with that key sequence. – phils Jun 7 '17 at 20:53
2

In addition to what @phils said:

I too don't know of a way to get back to the location of the first replacement, after you've already moved on from there.

But if you think ahead of time that you might want to get back there, all you need to do is this:

  1. Use ., to make the first replacement and exit query-replace.

  2. Use C-SPC to set the mark at the end of that replacement.

  3. Use C-x ESC ESC (also C-x M-: and C-x M-ESC), to start the query-replace again.

(You might think that you could use C-r to enter a recursive edit, then C-SPC, and then C-M-c to resume query-replacing. But the effect of C-SPC is apparently lost.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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