Reputation: 4600
How can I selected, for instance, 5 lines of code, and replace all instance of myObject1
with myObject2
?
If subsequent lines of code contain myObject1
reference that I wish not to change. This way I can quickly apply of find & replaces in this scope of code very conveniently without worrying about side effects.
Is this possible?
Upvotes: 13
Views: 8018
Reputation: 16416
Yes, it is possible.
Edit > Find > Replace
or using the dedicated shortcut
Ctrl+R ( ⌘ R on Mac).Now if you press "Replace All", only the items found inside your selection will be replaced.
In the new UI of IntelliJ IDEA the "Search In Selection" option is in another place (kudos to @Chris for pointing this out):
Edit > Find > Replace
or using the dedicated shortcut
Ctrl+R ( ⌘ R on Mac).Now if you press "Replace All", only the items found inside your selection will be replaced.
You can also open the "Filter Search Results" dialog using the shortcut (Ctrl+Alt+F on Windows/Linux, ⌃⌥F on macOS), but in this case it is important that the cursor is inside the "Search" field.
In similar way you can perform just a search (i.e. without replace) inside a selected area in your files. Look inside the Edit > Find
menu for more interesting options.
Here is the official IntelliJ IDEA documentation that covers this topic: Find in selection.
Upvotes: 21