How to remove unused imports in Intellij IDEA on commit?

前端 未结 9 1625
遥遥无期
遥遥无期 2020-12-23 02:57

Is there a way to remove unused imports in Intellij IDEA on commit?

It is not very optimal to do it manually, CTRL + ALT + O helps b

相关标签:
9条回答
  • 2020-12-23 02:59

    In Mac IntelliJ IDEA, the command is Cmd + Option + O

    For some older versions it is apparently Ctrl + Option + O.

    (Letter O not Zero 0) on the latest version 2019.x

    0 讨论(0)
  • 2020-12-23 03:00

    In mac book

    IntelliJ

    Control + Option + o (not a zero, letter "o")

    0 讨论(0)
  • 2020-12-23 03:06

    Or you can do the following shortcut :

    MAC : Shift + Command + A (Enter Action menu pops up)

    And write : Optimize Imports

    0 讨论(0)
  • 2020-12-23 03:13

    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.

    0 讨论(0)
  • 2020-12-23 03:17

    When you commit, tick the Optimize imports option on the right. This will become the default until you change it.

    I prefer using the Reformat code option as well.

    0 讨论(0)
  • 2020-12-23 03:17

    In IntelliJ, select the project you want to optimize imports on, go to Code menu and choose Optimize imports and a small Optimize Imports popup window will appear. On the popup window you need to click on Run button. Or alternatively, on IntelliJ on Mac, you can use a keyboard short cut Option + Command + O

    0 讨论(0)
提交回复
热议问题