Eclipse Shortcut To Remove Unused Imports

Ctrl + Shift + O is the shortcut key to optimize or remove the unused import from your code in Eclipse or Spring Tool Suite (STS) for the Windows/Linux operating system.

To remove those unused imports automatically, just click on the class and press the shortcut “Ctrl + Shift + O” to initilize the “Organize imports” feature.

10 Answers 10 Sorted by:

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending. 264

I just found the way. Right click on the desired package then Source -> Organize Imports.

Shortcut keys:

  • Windows: Ctrl + Shift + O
  • Mac: Cmd + Shift + O
  • You can direct use the shortcut by pressing Ctrl+Shift+O

    I know this is a very old thread. I found this way very helpful for me:

  • Go to Window → Preferences → Java → Editor → Save Actions.
  • Check the option “Perform the selected actions on save”.
  • Check the option “Organize imports”.
  • Now every time you save your classes, eclipse will take care of removing the unused imports.

    Remove all unused import in eclipse:

    Right click on the desired package then Source->Organize Imports. Or You can direct use the shortcut by pressing Ctrl+Shift+O

    If you want to do this on whole project then inside project –>select src folder–>press Ctrl+Shift+O

    Use ALT + CTRL + O. It will organize all the imports. You can find various other options in the “Code” Menu.

    EDIT: Sorry it is CTRL + SHIFT + O

    Better way is just to add “save action” so when you save the project it will clear the unused imports and format the code as well if you like .

    Go to Window > Preferences > Java > Editor > Save Actions

    and pick what ever you want .

    press Ctrl+Shift+O and it will remove unwanted imports

    Certainly in Eclipse indigo, a yellow line appears under unused imports. If you hover over that, there will be multiple links; one of which will say “Remove unused import”. Click that.

    If you have multiple unused imports, just hover over one and there will be a link that allows you to remove all unused imports at once. I cant remember the exact wording off hand, but all the links that appear are pretty self explanatory.

    Not to reorganize imports (not to unfold .* and not to reorder lines) to have least VCS changeset you can use custom eclipse clenup as this answer suggests

    Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!
  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.
  • To learn more, see our tips on writing great answers. Draft saved Draft discarded

    Want to learn more about using shortcuts in Eclipse? Check out this post where we look at the Eclipse shortcut for removing all unused imports in a Java file.

    Join the DZone community and get the full member experience.

    Eclipse IDE gives the warning “The import XXX is never used” whenever it detects an unused import in a Java source file and shows a yellow underline. Though the unused import in a Java file does not create any harm, its unnecessary to increase the length and size of a Java source file, and if you have too many unused imports in your Java source file, those yellow underlines and Eclipse warnings affect the readability of your code. In my last post on Eclipse, we looked at some Java debugging tips on Eclipse. In this post, we will see an Eclipse shortcut to remove all unused imports in Eclipse. There are many options to tackle this problem, e.g. you can collapse the import section of code in Eclipse or you can altogether remove all unused imports from Java file, and well see them in this short tutorial.

    If you are completely new to Eclipse IDE, then I suggest you to first go through a comprehensive course, like The Eclipse Guided Tour: Part 1 and 2 from Pluralsight, which will teach you everything you need to know about Eclipse from the Java development point of view.

    Anyway, lets see how to remove all unused imports from a Java file in Eclipse IDE.

    1 Organize Imports from Source menu

    Few unused imports in the below Java class

    Click Source Menu –> Organize Imports


    How do I get rid of unused imports in Eclipse?

    Eclipse provide a shortcut CTRL + SHIFT + O, this shortcut command will remove all those unused imports from your code file.

    How do I get rid of unused imports?

    How about Android Studio ?

    I found this way very helpful for me:
    1. Go to Window → Preferences → Java → Editor → Save Actions.
    2. Check the option “Perform the selected actions on save”.
    3. Check the option “Organize imports”.

    What is the shortcut key for importing packages in Eclipse?

    Press: CTRL + SHIFT + O and you should see below dialog boxes. Choose your desired import package and click next. It will prompt you for your next import and thats it.

    How do I remove unused imports in entire project in Intellij?

    please use the default key combination below. CTRL + ALT + O —> to remove the unused imports in windows. However, you can also change the keymap of “Optimize Imports” in settings.

    Related Posts