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?

- 7,849
- 4
- 41
- 87
2 Answers
(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.

- 50,977
- 3
- 79
- 122
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:
Use
.
, to make the first replacement and exitquery-replace
.Use
C-SPC
to set the mark at the end of that replacement.Use
C-x ESC ESC
(alsoC-x M-:
andC-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.)

- 77,472
- 10
- 114
- 243
C-u C-SPC
? – Name Jun 07 '17 at 13:58M-x describe-key RET C-SPC
(orC-h k C-SPC
) reports that the key is bound to the commandset-mark-command
. – Basil Jun 07 '17 at 14:26(pop-to-mark-command)
is what is ultimately happening with that key sequence. – phils Jun 07 '17 at 20:53