Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unused import in Reformat Code in android studio

I know Ctrl+Shift+O shortcut key for remove unused import but is possible to remove unused import in reformat code in android studio.

Edit 1:

What i am looking for : A option for remove unused import when reformat code.reformat code option usually find in Preferences->Editor->Code Style->Java

like image 939
Saman Avatar asked Apr 15 '17 12:04

Saman


People also ask

How do you automatically remove unused imports in VS code?

As of Visual Studio Code Release 1.22 this comes free without the need of an extension. Shift + Alt + O will take care of you.

Can Isort remove unused imports?

Adding or removing an import from multiple files isort can be ran or configured to add / remove imports automatically.

How do I organize imports in Android Studio?

In Android Studio, there is a way to automatically organize imports as you type. If you are on a Mac, go to Android Studio -> Preferences (on Windows I think it's under File -> Settings), and then under Editor -> Auto Import, you can change the settings to look like this.


4 Answers

Open reformat file dialog (ctrl+shift+alt+L), there is an option there "Optimize import", select it and press run. Now whenever you reformat code (ctrl+alt+L) it will also optimize imports.

like image 82
lelloman Avatar answered Sep 27 '22 14:09

lelloman


In android studio Ctrl+Shift+O does not remove unused imports it is used in Eclipse, here we can use Ctrl+Alt+O to remove unused imports and Ctrl+Alt+l to format code.

like image 22
Chirag Jain Avatar answered Sep 25 '22 14:09

Chirag Jain


The "Optimize imports" option is in the "Reformat File Dialog". You could find the shortcuts in Preferences->Keymap with key word "Show Reformat File Dialog"

like image 22
Abner Zhong Avatar answered Sep 29 '22 14:09

Abner Zhong


For Mac use + + O
For Windows use Ctrl + Alt + O

Chill Pill :)

like image 25
Ali Akram Avatar answered Sep 25 '22 14:09

Ali Akram