364

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,102
  • 5
  • 23
  • 37
sirFunkenstine
  • 8,135
  • 6
  • 40
  • 57
  • 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

12 Answers12

708

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
  • 3,384
  • 5
  • 40
  • 64
Krylez
  • 17,414
  • 4
  • 32
  • 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
122

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,603
  • 6
  • 44
  • 104
sooglejay
  • 1,355
  • 1
  • 9
  • 15
68

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

Zoombie
  • 3,590
  • 5
  • 33
  • 40
19

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

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
Simon
  • 461
  • 1
  • 5
  • 23
16

Use ctrl+R or cmd+R in OSX

Arnaud
  • 7,259
  • 10
  • 50
  • 71
santaclos
  • 326
  • 3
  • 4
15

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,236
  • 2
  • 16
  • 32
7

The shortcuts are

On Windows : Ctrl+Shift+R

On Mac : Cmd+Shift+R

JGPhilip
  • 1,388
  • 17
  • 19
3

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

dazed
  • 352
  • 3
  • 9
2

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

Dinesh
  • 45
  • 2
2

This is very simple.

Use Ctrl+R for Windows .

Use Cmd+R for mac.

Deepak gupta
  • 827
  • 10
  • 10
1

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,646
  • 9
  • 39
  • 56
1

In Android studio,

  1. ctrl + r - will do find and replace with in a file
  2. ctrl + shift + r - will do find and replace in whole project

Find and replace with in file

Pranav Dave
  • 393
  • 5
  • 7