Kei Minagawa
Kei Minagawa

Reputation: 4521

Can I modify string that have already entered when using replace-string command in Emacs?

Replacement "A" with "B" will be executed as follow. My question is when I'm in phase 4, can I go back phase 2 and edit "A" again using some commands?

  1. M-x replace-string
  2. "A"
  3. RET
  4. "B"
  5. RET

Thanks.

Upvotes: 1

Views: 91

Answers (2)

Drew
Drew

Reputation: 30708

  1. Consider using query-replace instead.

    You mean query-replace can do it?

    Not sure what you mean by "it", but yes, IMO query-replace sounds like what you want. See the Emacs manual, node Query Replace. Not too that C-r lets you pause query-replacing to do whatever you want (e.g. editing) and then resume it again later.

  2. Another approach you might consider: Icicles on-demand replacement.

    It depends what kind of replacing you want to do and how much replacement you want to make. Icicles on-demand replacement is designed more as an adjunct to searching than as a systematic replacement technique.

    An advantage is that you do not need to visit each match in turn, and reply saying whether or not you want to replace it. You are not queried; it is you who decides where you want to perform a replacement.

    And likewise wrt to searching: you need not visit each search hit, in order. You can visit any search hits that you like, in any order, and cycle among any subsets of them. You can even sort the search hits in various ways, which affects both ease of access/visibility and cycling order.

Overall, I'd suggest that you start by taking a look at the query-replace doc. If your use case does not, in fact, correspond to what query-replace (or Icicles replacement) provides, then perhaps elaborate about your use case in your description.

Upvotes: 1

Tom
Tom

Reputation: 7586

If you are worried about the loss of A and B, because you don't want to type them again then go to step 5 (press RET after B) and then press undo (I see you use replace-string, instead of query-replace, so you need to undo your changes). This way both inputs are stored in the minibuffer history and when you start the command again you can access them with the up arrow.

Upvotes: 1

Related Questions