How to enable "remove unused imports"

Answered

I don't see it under Settings | Code | Imports..

I'm using 10.5.1

2
8 comments
Avatar
Permanently deleted user

Preferences->Editor->Auto Import->Optimize Imports on the Fly will automatically remove unuxed imports.

7

thx that's what I was looking for

0
Avatar
Permanently deleted user

On Fri, 23 Sep 2011 19:42:34 MSD, Stephen Boesch
<no_reply@jetbrains.com> wrote, quoted or indirectly quoted someone
who said :

>I don't see it under Settings | Code | Imports.

I prefer to it manually, as part of reformat code.

If it tidies code which in a chaotic state, e.g. you have just pasted
in a mess of code from elsewhere, you often find that it tosses out
all kinds of GOOD imports.  You then have to tediously recreate them.

I don't tidy until I have a clean compile.
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

1

For anyone looking for this ten years later, the option has moved slightly to:

Preferences->Editor->General->Auto Import->Optimize Imports on the Fly

4

Thanks Thomas Kelley, I've enabled the optimize imports but turns out I also have to enable it on General

0

Is there any way to just remove the unused imports instead of completely moving them around? It is a nightmare when people use different IDEs that "optimize" their imports in the way they feel like it is a good idea. I've seen commits that are literally just imports being moved around by the IDE or the guy who uses Eclipse removing the `.*` and the guy who uses IntelliJ bringing them back and then conflicts happen on these imports

0

Guilherme Taffarel Bergamin

You can remove all of the rules specified in Settings/Preferences | Editor | Code Style | <language> | Imports. Then hitting Ctrl+Alt+O (on Windows) will just remove unused imports, no moving them around.

E.g. for Java, see https://www.jetbrains.com/help/idea/2022.2/code-style-java.html#imports_table

0

Please sign in to leave a comment.