14
votes

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

4
you can format your code using Ctrl+Shift+F - Andy Developer
@AndyDeveloper I know but with default configuration format code not removed unused import - Saman
So what is the problem. You need both the thing with one shortcut key? - Andy Developer
@AndyDeveloper yes . in phpstorm you can use some thing like this and i guess this place would have - Saman
You can change the keyboard shortcut. Goto Preferences->KeyMap-> here you search for reformat code and unused import you can set the both with same shortcut key. Well I am not sure whether it is working or not because as for I know it will not allow to set both the operation using one shortcut key but you can try it out. - Andy Developer

4 Answers

51
votes

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.

9
votes

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.

3
votes

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"

0
votes

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

Chill Pill :)