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 tooltip prompting you to add a missing import statement so that you don't have to add it manually. Press AltEnter to accept the suggestion.
If there's more than one possible source of import, pressing AltEnter will open the list of suggestions.
![the auto-import tooltip the auto-import tooltip](https://resources.jetbrains.com/help/img/idea/2024.3/go_auto_import.png)
You can configure the IDE to automatically add import statements if there are no options to choose from.
Press CtrlAlt0S to open settings and then select Go | Imports.
Select the Add unambiguous imports on the fly checkbox, and apply the changes.
If you want to completely disable auto-import, make sure that:
The automatic insertion of import statements is disabled.
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.
Press CtrlAlt0S to open settings and then select Go | Imports.
In the Exclude from auto-import and completion section, click
AltInsert, 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).
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 Settings | Editor | Code Style | <language> | Imports.
tip
You can exclude specific files and folders from import optimization. For more information, refer to Exclude files from reformatting.
Select a file or a directory in the Project tool window (View | Tool Windows | Project).
Do any of the following:
In the main menu, go to Code | Optimize Imports (or press CtrlAlt0O).
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 your project is under version control), and click Run.
Place the caret at the import statement and press AltEnter or use the
icon.
Select Optimize imports.
![Remove use statement Remove use statement](https://resources.jetbrains.com/help/img/idea/2024.3/go_optimize_imports.png)
tip
To optimize imports in a file, you can also press CtrlAltShift0L, select Optimize imports, and click Run.
If your project is under version control, you can configure GoLand to optimize imports in modified files before committing them to VCS.
note
Press Alt00 to open the Commit tool window and click Show Commit Options
.
Click
and in the commit message area, select the Optimize imports checkbox.
You can configure the IDE to optimize imports in modified files automatically when your changes are saved.
Press CtrlAlt0S to open settings and then select Tools | Actions on Save.
Enable the Optimize imports option.
Additionally, from the All file types list, select the types of files in which you want to optimize imports.
Apply the changes and close the dialog.
You can tell GoLand to optimize imports in a file every time it is reformatted.
Open the file in the editor, press CtrlAltShift0L, and make sure the Optimize imports checkbox is selected in the Reformat File dialog that opens.
After that every time you press CtrlAlt0L in this project, GoLand will optimize its imports automatically.
When you use this grouping, GoLand puts all imports that begin with the specified string after third-party packages.
Open settings by pressing CtrlAlt0S and navigate to Editor | Code Style | Go. .
Click the Imports tab.
From the Sorting type list, select goimports.
Select the Group checkbox.
Click the Imports starting with radio button and type the grouping prefix in the text field.
Thanks for your feedback!