Does IntelliJ have an Organize Imports feature similar to that in Eclipse? What I have is a Java file with multiple classes missing their imports. Example:
p
That plugin will automatically do the "organize import" action on file save: https://github.com/dubreuia/intellij-plugin-save-actions.
To install: "File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'". Then activate the "organize import" save action.
In addition to Optimize Imports
and Auto Import
, which were pointed out by @dave-newton and @ryan-stewart in earlier answers, go to:
File menu > Settings > Code Style > Java > Imports
File menu > Settings > Editor > Code Style > Java > Imports
(thanks to @mathias-bader for the hint!)
There you can fine tune the grouping and order or imports, "Class count to use import with '*'
", etc.
Note:
since IDEA 13 you can configure the project default settings from the IDEA "start page": Configure > Project defaults > Settings > ...
. Then every new project will have those default settings: