389

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 I'm working on. I've been doing it for about an hour and I know I'm wasting my time. Let me know of any time-saving suggestions.

1
  • 1
    One way to do it is right click in the solution on the folder structure and there choose replace in path. Commented Apr 2, 2014 at 11:54

12 Answers 12

749

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

Sign up to request clarification or add additional context in comments.

8 Comments

I'm on OS X and it was still Ctrl+Shift+R
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.
at OS X at least for me was Command instead of Ctrl button. Just for the new mac - android studio users.
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.
also Ctrl + Shift + R for Ubuntu(Linux)
|
123

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

Comments

69

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

1 Comment

This is the correct answer in Android Studio on macOS. The only full-project search/replace sweeper.
19

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

Comments

16

Use ctrl+R or cmd+R in OSX

1 Comment

this is only affect to current open file
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.

1 Comment

The default shortcut for rename is Shift + F6. ;-)
13

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

Comments

8

The shortcuts are

On Windows : Ctrl+Shift+R

On Mac : Cmd+Shift+R

Comments

3

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

Comments

2

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

1 Comment

But it does not give replace option.
2

This is very simple.

Use Ctrl+R for Windows .

Use Cmd+R for mac.

1 Comment

This will search/replace on the current file, not in the entire project
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.