Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all unused imports from current project in Intellij Idea

I have been using Intellij Idea for quite some time now. I have a few questions though. Is there a way to delete all unused imports from all files in the current project?

I know that I can choose menu item Code > Optimize Imports (CTRL + ALT + O) to organize imports in individual files but since the application that I am working on has hundreds of files, this process does not make any sense. If there is no way of doing this, can I create a macro for this? If so, how do I do it?

like image 797
Prashant Avatar asked Aug 14 '18 04:08

Prashant


People also ask

How do I remove unused imports from whole project in IntelliJ?

CTRL + ALT + O ---> to remove the unused imports in windows. However, you can also change the keymap of "Optimize Imports" in settings.

How do I delete unused imports in project?

Key combination Ctrl+ Shift + O - will trigger the Organize Imports that will remove and add missing imports. It is for single file only. It can be applied to entire projects too, or you can right click on a project and select it from the 'Source' menu.

How do I fix all imports in IntelliJ?

Optimize all importsFrom the main menu, select Code | Optimize Imports (or press Ctrl+Alt+O ). From the context menu, select Optimize Imports.

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.


1 Answers

Click the project folder, then enter CTRL + ALT + O. It will handle all files under the folder:

enter image description here

like image 69
xingbin Avatar answered Sep 23 '22 17:09

xingbin