How to undo in Intellij IDEA replace in files?
Asked Answered
W

2

7

In intellij 2022.1, I use Ctrl+Shift+R to bring up the Replace in Files window - it shows 100+ matches in 40+ files. The search string and the replace string differ in only one character, for example: this.bar.is.fooed and this.barf.is.fooed. I only need to replace certain instances based on nearby text.

I'm in the groove, clicking the Replace button, checking the next entry, clicking, checking, ... and thinking my brain can keep things straight (it can't; neither can yours:-) I'm halfway through when I realize the last few replaces were wrong.

How can I undo them? Ctrl+Z is grayed out. This related SO question doesn't say and neither does the JetBrains documentation!

Wickerwork answered 28/4, 2022 at 17:7 Comment(3)
Use Local History to revert the changes: jetbrains.com/help/idea/local-history.html. Undo/redo is not supported for Replace dialog, vote for the related request at youtrack.jetbrains.com/issue/IDEA-265341.Stinkstone
Thanks for the link. I'm surprised I was the first vote on that one.Wickerwork
@Stinkstone If you post your comment as an answer, I'll accept it.Wickerwork
S
5

Use Local History to revert the changes.

Undo/redo is not supported for Replace dialog, vote for the related request.

Stinkstone answered 3/6, 2022 at 15:49 Comment(2)
How does it help to undo last changes in multiple files?Colonnade
@Colonnade the local history will have a line per file. If the find and replace modified X files, there will be a line for X files. Just navigate to the history prior to these files and revert from there.Urethra
K
3

For those not familiar with the "Show Local History" workflow:

  1. Bring up the Project Pane and right-click on the root of the project.

  2. In the right-click context menu, go to Local History > Show Local History....

  3. In the History Pane, select the edits you want to revert (if you mistakenly hit Replace all, then there will be an edit called Replace all).

  4. Finally, right click on the edits you selected and select Revert from the context menu.

Kenwrick answered 5/2 at 21:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.