When searching for a string with C-s
, I want to be able to hit some key to exit search mode but still maintain the selection of the match. That way I can immediately start typing and replace the last match.
For example, say I have the following document:
The quick brown fox jumps over the lazy dog.
If I search for "lazy", emacs will select that word like so (square brackets are selection, pipe is cursor):
The quick brown fox jumps over the [lazy|] dog.
Now, if I press return, emacs will maintain my cursor position, but it will deselect "lazy":
The quick brown fox jumps over the lazy| dog.
Instead of this, I want a shortcut that will exit search mode but maintain the current match selection, like in the second state above.
M-x query-replace
what you're looking for?C-s
and type what I think I want to search for, then change the query w/ backspace to zero in on the thing I want to change. Then I play around with what exactly I want to replace it with.M-%
is too "formal."query-replace
doesn’t solve this.