324

Is there a way to find and replace all occurrences of a word in an entire project( not just a single class using refactor -> rename) and also maintain case, either in android studio or using a command line script?

For example, Supplier has to go to Merchant, supplier -> merchant, SUPPLIER -> MERCHANT. My boss wants me to change all instances of supplier with merchant for a project im working on. Ive been doing it for about an hour and i know im wasting my time. Let me know of any time saving suggestions.

Davis Broda
  • 4,051
  • 5
  • 23
  • 36
sirFunkenstine
  • 7,505
  • 6
  • 37
  • 54
  • 1
    One way to do it is right click in the solution on the folder structure and there choose replace in path. – Johan Apr 02 '14 at 11:54

11 Answers11

633

I think the shortcut that you're looking for is:

Ctrl+Shift+R on Windows and Linux/Ubuntu

Control+Shift+R on macOS (IntelliJ IDEA Classic keymap)

Cmd+Shift+R on macOS (macOS keymap)

ref: source

George
  • 2,964
  • 5
  • 38
  • 60
Krylez
  • 16,594
  • 4
  • 31
  • 41
  • 9
    I'm on OS X and it was still Ctrl+Shift+R – CodyMace Jul 31 '14 at 17:55
  • 3
    This worked wonderfully! I had to rename a class in it's entirety, including comments, getters, setters, constructors, new calls, THE WORKS, but android studio's refactor was bugging out on me. Ctrl+Shift+R however, ignored all that and hard changed the files after which the project had to be reloaded. Do select "preserve case" or it will mess up everything. – G_V Nov 06 '14 at 14:48
  • 4
    at OS X at least for me was Command instead of Ctrl button. Just for the new mac - android studio users. – karvoynistas Feb 11 '15 at 17:01
  • 4
    Doesn't work for me anymore. I think this shortcut was removed. Anyone else seeing the same? Edit>Find>Replace In Path is still there of course. – Da-Jin Feb 06 '16 at 16:19
  • Command-Shift-R brings up Replace in Path dialogue for me in OSX El Capitan, Android Studio 2.1.3. – user1147171 Sep 05 '16 at 20:05
  • 1
    also `Ctrl + Shift + R` for Ubuntu(Linux) – Morozov Aug 18 '17 at 08:10
  • On Mac OS it is `CMD` + `R` – Rawand Saeed Jul 28 '21 at 19:44
  • On all platforms, you can go to Preferences>Keymap, then search "Replace" to see keymaps for "replace"-related commands. This is especially helpful if you're not using the default keymap – Darwin Huang Oct 05 '21 at 14:14
105

On Windows:

Find : Ctrl+F

Find And Replace In Single Class: Ctrl+R

Find And Replace In Whole Project: Ctrl+Shift+R

on OS X ,it is similar, just replace Ctrl with Command

Fabrizio
  • 7,190
  • 6
  • 37
  • 86
sooglejay
  • 1,185
  • 1
  • 8
  • 15
60

In Android studio, Edit -- > Find --> Replace in path, this will check in whole project including comments and code.

Zoombie
  • 3,480
  • 4
  • 31
  • 40
16

Press Ctrl+R to find and replace codes in the class where you are...

Fabrizio
  • 7,190
  • 6
  • 37
  • 86
Simon
  • 409
  • 1
  • 5
  • 23
14

Use ctrl+R or cmd+R in OSX

Arnaud
  • 6,869
  • 8
  • 49
  • 68
santaclos
  • 305
  • 3
  • 4
13

If you use refactor->rename for the name of the file, everywhere the file is used in your project the refactor will replace it.

I have already rename variables, xml file, java file, multiple drawable and after the operation I could build directly without error.

Do a back-up of your project and try to see if it work for you.

Pull
  • 2,116
  • 2
  • 15
  • 31
5

The shortcuts are

On Windows : Ctrl+Shift+R

On Mac : Cmd+Shift+R

JGPhilip
  • 1,232
  • 16
  • 19
3

Try using: Edit -> Find -> Replace in path...

dazed
  • 344
  • 3
  • 9
2

ctrl + H ..... its give option to replace word from class.

Dinesh
  • 45
  • 2
2

I think the previous answers missed the most important (non-trivial) aspect of the OP's question, i.e., how to perform the search/replace in a "time saving" manner, meaning once, not three times, and "maintain case" originally present.

On the pane, check "[X] Preserve Case" before clicking the Replace All button

This performs a case-aware "smart" replacement in one pass:

apple -> orange
Apple -> Orange
APPLE -> ORANGE

Also, for peace of mind, don't forget to check the code into the VCS before performing sweeping project-wide replacements.

Pete Alvin
  • 4,446
  • 8
  • 37
  • 55
-1

This is very simple.

Use Ctrl+R for Windows .

Use Cmd+R for mac.

Deepak gupta
  • 597
  • 7
  • 9