5.7.1 Review replacements one at a time

Use a disposable Text-mode buffer for this example. Insert these three lines:

The draft is ready.
Keep this draft for comparison.
The draft outside the selection must stay unchanged.
  1. From the beginning, set the mark with C-SPC and move down two lines. Point is at the third line’s beginning. C-e r should read only the first two lines. Keep this region active for the next command.
  2. Press M-% to start query replacement. At the first prompt enter draft and press RET; at the second enter version and press RET. These are answers to successive prompts, not text inserted into the document.
  3. Emacsvox reads the line containing the proposed match. Press y to replace the first occurrence. At the second, press n to leave it unchanged.
  4. When the command finishes, read all three lines. Only the first should say version. The second was skipped and the third was outside the selection.

M-x query-replace RET is an alternative when Meta-percent is difficult to enter. The active region limits the operation under normal Transient Mark mode; without it, ordinary forward query replacement works from point towards the accessible buffer end. Do not deactivate or replace the checked mark between selection and starting the command. For a full-document operation, first abandon unrelated selection and deliberately choose the starting point.

At a replacement question, q or RET stops without changing further matches; earlier replacements remain. Comma, ,, replaces the current match and lets you review it before advancing. ! replaces the remaining matches without more questions and is not needed for this guided task. Other editing keys can leave the replacement loop and then act on the document. Rely on the automatic match reading, or stop before issuing ordinary speech/editing keys.

Check the result before saving. Use Recover a text edit before saving if the scope or replacement was wrong. Replacement commands and Query replace in the GNU Emacs Manual cover exact matching, case behaviour and the full set of answers. Regular-expression replacement is a different, more specialised task.