Auto import
If you use a type, an interface, a method, or a function that you haven't imported yet, the IDE shows you a popup suggesting to add a missing import statement so that you don't have to add it manually. Press Alt+Enter to accept the suggestion.
If there's more than one possible source of import, pressing Alt+Enter will open the list of suggestions.
Automatically add import statements
You can configure the IDE to automatically add import statements if there are no options to choose from.
In the Settings/Preferences dialog Ctrl+Alt+S, click .
Select the Add unambiguous imports on the fly checkbox, and apply the changes.
Disable import popups
When popups are disabled, unresolved references are underlined and marked with the red bulb icon .
Disable all popups
Hover the mouse over the inspection widget in the top-right corner of the editor, click , and disable the Show Auto-Import Tooltip option.
The Show Auto-Import Tooltip option toggles the auto-import feature. The setting does not influence the auto import functionality when you select constraints from the code completion list.
Exclude packages from auto import
The list of import suggestions may include packages that you don't need. You can exclude redundant entries from automatic import so that the list of suggestions contains only relevant items.
In the Settings/Preferences dialog Ctrl+Alt+S, click .
In the Exclude from auto-import and completion section, click Alt+Insert, and specify a class or a package that you want to exclude.
You can also select whether you want to exclude items from the current project or from all projects (globally).
Optimize imports
The Optimize Imports feature helps you remove unused imports and organize import statements in the current file or in all files in a directory at once according to the rules specified in .
Optimize all imports
Select a file or a directory in the Project tool window ( ).
Do any of the following:
From the main menu, select
(or press Ctrl+Alt+O ).From the context menu, select Optimize Imports.
(If you've selected a directory) Choose whether you want to optimize imports in all files in the directory, or only in locally modified files (if yor project is under version control), and click Run.
Optimize imports in a single file
Place the caret at the import statement and press Alt+Enter or use the icon.
Select Optimize imports.
Automatically optimize imports in modified files
If your project is under version control, you can instruct GoLand to optimize imports in modified files before committing them to VCS.
From the main menu, select
(or press Ctrl+K ).Click and in the Before commit area, select the Optimize imports checkbox.