sirFunkenstine
sirFunkenstine

Reputation: 8495

Find and replace Android studio

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.

Upvotes: 385

Views: 345946

Answers (12)

Pranav Dave
Pranav Dave

Reputation: 804

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

Upvotes: 9

Krylez
Krylez

Reputation: 17800

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

Upvotes: 740

Deepak gupta
Deepak gupta

Reputation: 947

This is very simple.

Use Ctrl+R for Windows .

Use Cmd+R for mac.

Upvotes: 2

Pete Alvin
Pete Alvin

Reputation: 4778

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.

Upvotes: 1

JGPhilip
JGPhilip

Reputation: 1498

The shortcuts are

On Windows : Ctrl+Shift+R

On Mac : Cmd+Shift+R

Upvotes: 8

Simon
Simon

Reputation: 471

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

Upvotes: 19

sooglejay
sooglejay

Reputation: 1375

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

Upvotes: 124

dazed
dazed

Reputation: 372

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

Upvotes: 3

santaclos
santaclos

Reputation: 326

Use ctrl+R or cmd+R in OSX

Upvotes: 16

Dinesh
Dinesh

Reputation: 45

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

Upvotes: 2

Zoombie
Zoombie

Reputation: 3610

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

Upvotes: 68

Pull
Pull

Reputation: 2246

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.

Upvotes: 15

Related Questions