Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent IntelliJ IDEA from deleting unused packages?

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?

like image 285
Seyed Vahid Hashemi Avatar asked Jun 22 '12 11:06

Seyed Vahid Hashemi


People also ask

How do I fix an unused import in IntelliJ?

Choose the project/module you want to remove unused import from in Project view. Then from Code menu choose Optimize imports and confirm with Run. The imports will be cleaned in whole project/module.

How do I prevent wildcard imports in IntelliJ?

Disable wildcard importsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.

How do I disable optimize imports in IntelliJ?

4 Answers. Show activity on this post. 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.

How do I automatically import packages in IntelliJ?

Use Alt + Enter for importing a single package or use Alt + Shift + Enter to auto import all the unambiguous packages in the current file.


2 Answers

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.

like image 101
CrazyCoder Avatar answered Sep 18 '22 21:09

CrazyCoder


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: 

enter image description here

like image 36
Sasha Avatar answered Sep 18 '22 21:09

Sasha