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.
In IntelliJ, in a . java file, some unused code is greyed out indicating that the declared variable or function is never used. Unused imports are removed using Ctrl+Alt+O.
In IntelliJ IDEA, Ctrl + Alt + O is the shortcut keys to remove/optimize unused imports for Windows/Linux operating system, and control + option + O is for Mac OS.
In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.
If you are using IntelliJ IDEA or Android Studio:
Go to Settings > Editor > General >Auto Import and check the Optimize imports on the fly checkbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With