CLion 2019.1 Help

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

  1. Place the caret at the Project tool window and do one of the following:

    • On the main menu, choose Code | Optimize Imports.

    • Press Ctrl+Alt+O.

    The Optimize Imports dialog box opens.

  2. If your project is under version control, the option Only VCS changed files is enabled. Select or clear this option as required.

  3. 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

  1. On the main menu, choose Code | Optimize Imports.

  2. Press Ctrl+Alt+O.

  3. Place the caret at the import statements, click icons actions intentionBulb svg, and choose Remove unused import.

  4. 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.

  1. From the main menu, select VCS | Commit (or press Ctrl+K).

  2. In the Before commit area of the Commit Changes dialog, select the Optimize imports checkbox.

Last modified: 12 June 2019

See Also