How to prevent IntelliJ IDEA from deleting unused

2019-01-08 21:03发布

问题:

I'm working with intelliJ and my problem is when I start to import some temporary unused packages into my class file intellij delete those line within a second.

how can I turn off this not so nice feature?

回答1:

Disable Settings | Editor | General | Auto Import | Optimize imports on the fly.

Normally you don't need to add imports manually, IDEA does it for you.



回答2:

For Scala developers: you can have enabled

Settings > Editor > General > Auto Import > Optimize imports on the fly

but add exclusions into

Settings > Editor > Code Style > Scala > Imports always marked as used:



回答3:

In Intellij 14 : Settings > Editor > General > Auto Import > Optimize imports on the fly.



回答4:

(Update) For the Scala developers out there, you can have 1/2 the cake and eat the other 1/2 now: disable the auto-optimize for just scala