Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove unused imports in Intellij IDEA on commit?

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.

like image 581
Leonid Avatar asked Oct 08 '22 10:10

Leonid


People also ask

How do I delete unused variables in IntelliJ?

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.

How do I remove unwanted imports in IntelliJ Mac?

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.

How do I manage imports in IntelliJ?

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.


1 Answers

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.

like image 84
Madan Sapkota Avatar answered Oct 15 '22 05:10

Madan Sapkota