Optimize Imports
The Optimize Imports feature helps you remove unused imports, add missing imports, and organize import statements in the current file or in all the files in a directory at once.
Optimize imports in the project
-
Place the caret at the Project tool window and do one of the following:
On the main menu, choose
.Press Ctrl+Alt+O.
The Optimize Imports dialog box opens.
If your project is under version control, the option Only VCS changed files is enabled. Select or clear this option as required.
Click Run.
One way of dealing with unused import is to use the quick-fix that appears when you set the caret at the highlighted unused import or include. However, you can optimize imports in a larger scope as described below.
Optimize imports in the current file
On the main menu, choose
.Press Ctrl+Alt+O.
Place the caret at the import statements, click
, and choose Remove unused import.
Open the Reformat File Dialog (Ctrl+Shift+Alt+L) and select the Optimize imports checkbox.
Automatically optimize imports in modified files
If your project is under version control, you can instruct CLion to optimize imports in modified files before committing them to VCS.
From the main menu, select
(or press Ctrl+K).In the Before commit area of the Commit Changes dialog, select the Optimize imports checkbox.