Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimize imports on the fly not working

I want imports to be deleted immediately after they become unused, so I checked Editor | General | Auto Import | Optimize imports on the fly, but it doesn't work.

like image 766
user2115763 Avatar asked Feb 13 '15 02:02

user2115763


People also ask

How do you optimize imports?

To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.

How do I fix unused import in Pycharm?

Optimize imports The Optimize Imports feature helps you remove unused imports and organize import statements in the current file or in all files in a directory at once according to the rules specified in Settings/Preferences | Editor | Code Style | <language> | Imports.

Do not import * IntelliJ?

To avoid IntelliJ IDEA replacing imports with * , you need to configure the Class count to use import with '*' and Names count to use static import with '*' preferences: Go to Preferences > Editor > Code Style > Java.


2 Answers

If Optimize imports on the fly is selected as you have done, then unused imports should definitely be removed automatically, given that:

  1. the file is recognized as a java file (it is located in a package under a Source Route.

and

  1. the file is modified in some way (hit enter on a black line anywhere in the file, this will trigger imports optimization).

To optimize imports in many files at once, you can use ctrl+alt+O, or you can also tick Optimize Imports option when you check in files to source control (for example svn).

like image 176
vikingsteve Avatar answered Sep 21 '22 18:09

vikingsteve


Please make sure that under Java | Imports, the Unused import (editor light) inspection is enabled.

like image 21
Atom 12 Avatar answered Sep 19 '22 18:09

Atom 12