如何在每次保存 IntelliJIDEA 后自动优化导入

我想学习如何能像我们做 Eclipse (保存行动)一样做到 每次保存后自动优化导入

53900 次浏览

IntelliJ IDEA offers an option to Optimize imports on the fly in Settings | Editor | General | Auto Import and Optimize imports option in the Commit Project dialog.

The mentioned answer works, but there is also the Intellij "save actions" plugin available from the JetBrains plugin repository that does that (as well as other things): Intellij Save Actions Plugin.

Installation

File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'

Disclaimer

I'm the plugin developer

In version 'Ultimate 2016.2' it is:

File > Other Settings > Default Settings > Auto Import > Optimize imports on the fly

First step:

CTRL + SHIFT + A or CMD + SHIFT + A (for mac)

Second step:

Search Optimize imports

Third step:

Switch ON the option

enter image description here