How to remove unused imports in Intellij IDEA on c

2020-02-16 07:24发布

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 but it's still manual.

9条回答
forever°为你锁心
2楼-- · 2020-02-16 07:58

You can check checkbox in the commit dialog.

enter image description here

You can use settings to automatically optimize imports since 11.1 and above.

enter image description here

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-02-16 08:07

If you are using IntelliJ IDEA or Android Studio:

Android optimize imports

Go to Settings > Editor > General >Auto Import and check the Optimize imports on the fly checkbox.

查看更多
地球回转人心会变
4楼-- · 2020-02-16 08:09

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.

查看更多
迷人小祖宗
5楼-- · 2020-02-16 08:11

File/Settings/Inpsections/Imports and change "Unused import" to Error. This marks them more clearly in the Inspections gutter and the Inspection Results panel.

查看更多
Emotional °昔
6楼-- · 2020-02-16 08:14

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

查看更多
Emotional °昔
7楼-- · 2020-02-16 08:16

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.

查看更多
登录 后发表回答