When I type the name of a class which will need to be imported, IntelliJ lovingly pops up with a list of suggestions. However, most of the time those suggestions are things I'd never want to import, especially by accident -- like java.awt.*
.
Is there a way to prevent the packages I'll never import from appearing in the completion list?
I've scoured the options but I haven't found anything.
Disable File | Settings | Editor | General | Auto Import | Optimize imports on the fly. Normally you don't need to add imports manually, IDEA does it for you. While this the common case in Java, with Scala and implicit conversions, things are not as smooth.
Start typing. By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.
To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.
Depending on the IDEA version: Yes.
In 7.0.5 use menu File -> Settings
choose Code Completion
and then Exclude from Import and Completion
and add the package or class that you don't want to have in your suggestions.
In version 8 and version 9 use menu File -> Settings
type "Auto import" into the search box and use the Exclude from Import and Completion
box there.
In version 9 you also have the option of adding Classes and Packages to the exclude-list directly from the import suggestions context-menu:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With