# Auto import

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/go/2026.3/llms.txt).

> **TL;DR**
> By default, GoLand uses `goimports`-style import sorting

If you use a type, an interface, a method, or a function that you have not imported yet, the IDE shows you a tooltip prompting you to add a missing import statement so that you do not have to add it manually. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Ctrl+.` (VSCode), `⌘ .` (VSCode (macOS)) to accept the suggestion.

If there's more than one possible source of import, pressing `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Ctrl+.` (VSCode), `⌘ .` (VSCode (macOS)) will	open the list of suggestions.

![the auto-import tooltip](https://resources.jetbrains.com/help/img/idea/2026.3/go_auto_import.png)

## Automatically add import statements

Procedure:

You can configure the IDE to automatically add import statements if there are no options to choose from.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Comma` (VSCode), `⌘ Comma` (VSCode (macOS)) to open settings and then select `Go | Imports`.

2. Select the Add unambiguous imports on the fly checkbox, and apply the changes.

![Add unambiguous imports on the fly checkbox](https://resources.jetbrains.com/help/img/idea/2026.3/go_add_imports.png)

## Disable auto import

If you want to completely disable auto-import, make sure that:

* The [automatic insertion of import statements](#automatically-add-import-statements) is disabled.

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

Procedure:

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Comma` (VSCode), `⌘ Comma` (VSCode (macOS)) to open settings and then select `Go | Imports`.

2. Under Exclude from import and completion, click ![Add](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg) and enter the import path to exclude, for example, `example.com/legacy`. Click OK.

The exclusion applies to the current project. It removes the package and packages below that path from automatic import and code completion suggestions.

Procedure: Exclude a package from the completion popup

1. In the code completion popup, select a suggestion from the package you want to exclude.

2. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Ctrl+.` (VSCode), `⌘ .` (VSCode (macOS)) and select the exclusion action for the import path, for example, Exclude 'example.com/legacy'. Select a parent path to exclude that package and all packages below it.

You can review or remove exclusions in `Settings | Go | Imports`.

## 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 `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](reformat-and-rearrange-code.html#exclude_file_from_reformat).

Procedure: Optimize all imports

1. Select a file or a directory in the Project tool window (`View | Tool Windows | Project`).

2. Do any of the following:

* In the main menu, go to `Code | Optimize Imports` (or press `Ctrl+Alt+O` (Windows), `⌃ ⌥ O` (macOS), `⌘ ⌥ O` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ O` (macOS System Shortcuts), `Ctrl+Alt+O` (XWin), `Ctrl+Alt+O` (GNOME), `Ctrl+Alt+O` (KDE), `Ctrl+Alt+O` (Emacs), `Ctrl+Alt+O` (Sublime Text), `⌃ ⌥ O` (Sublime Text (macOS)), `Alt+Shift+O` (VSCode), `⌥ ⇧ O` (VSCode (macOS))).

* From the context menu, select Optimize Imports.

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

Procedure: Optimize imports in a single file

1. Place the caret at the import statement and press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Ctrl+.` (VSCode), `⌘ .` (VSCode (macOS)) or use the ![the Intention action button](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.codeInsight.intentionBulb.svg) icon.

2. Select Optimize imports.

![Remove use statement](https://resources.jetbrains.com/help/img/idea/2026.3/go_optimize_imports.png)

> **Tip:**
> To optimize imports in a file, you can also press `Ctrl+Alt+Shift+L` (Windows), `⌘ ⌥ ⇧ L` (macOS), `⌘ ⌥ ⇧ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ L` (macOS System Shortcuts), `Ctrl+Alt+Shift+L` (XWin), `Ctrl+Alt+Shift+L` (GNOME), `Ctrl+Alt+Shift+L` (KDE), `Ctrl+Alt+Shift+L` (Emacs), `Ctrl+Alt+Shift+L` (Sublime Text), `⌘ ⌥ ⇧ L` (Sublime Text (macOS)), `Ctrl+Alt+Shift+L` (VSCode), `⌘ ⌥ ⇧ L` (VSCode (macOS)), select Optimize imports, and click Run.

Procedure: Optimize imports on commit

If your project is under version control, you can configure GoLand to optimize imports in modified files before committing them to VCS.

> **Note:**
> This feature is only available for [Git](using-git-integration.html) and [Mercurial](using-mercurial-integration.html).

1. Press `Alt+0` (Windows), `⌘ 0` (macOS), `⌘ 0` (IntelliJ IDEA Classic (macOS)), `⌘ 0` (macOS System Shortcuts), `Alt+0` (XWin), `Alt+0` (GNOME), `Alt+0` (KDE), `Alt+0` (Emacs), `Alt+0` (Sublime Text), `⌘ 0` (Sublime Text (macOS)), `Alt+0` (VSCode), `⌘ 0` (VSCode (macOS)) to open the Commit tool window and click Show Commit Options ![the Settings button](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.settings.svg).

2. Click ![Show Commit Options](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.settings.svg) and in the commit message area, select the Optimize imports checkbox.

![advanced commit options popup](https://resources.jetbrains.com/help/img/idea/2026.3/go_VCS_advanced_commit_options.png)

Procedure: Automatically optimize imports on save

You can configure the IDE to optimize imports in modified files automatically when your changes are [saved](saving-and-reverting-changes.html).

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Comma` (VSCode), `⌘ Comma` (VSCode (macOS)) to open settings and then select `Tools | Actions on Save`.

2. Enable the Optimize imports option.

Additionally, from the All file types list, select the types of files in which you want to optimize imports.

3. Apply the changes and close the dialog.

Procedure: Optimize imports when reformatting a file

You can tell GoLand to optimize imports in a file every time it is reformatted.

1. Open the file in the editor, press `Ctrl+Alt+Shift+L` (Windows), `⌘ ⌥ ⇧ L` (macOS), `⌘ ⌥ ⇧ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ L` (macOS System Shortcuts), `Ctrl+Alt+Shift+L` (XWin), `Ctrl+Alt+Shift+L` (GNOME), `Ctrl+Alt+Shift+L` (KDE), `Ctrl+Alt+Shift+L` (Emacs), `Ctrl+Alt+Shift+L` (Sublime Text), `⌘ ⌥ ⇧ L` (Sublime Text (macOS)), `Ctrl+Alt+Shift+L` (VSCode), `⌘ ⌥ ⇧ L` (VSCode (macOS)), and make sure the Optimize imports checkbox is selected in the Reformat File dialog that opens.

2. Click Run to reformat the file and optimize its imports.

After that every time you press `Ctrl+Alt+L` (Windows), `⌘ ⌥ L` (macOS), `⌘ ⌥ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ L` (macOS System Shortcuts), `Ctrl+Alt+L` (XWin), `Ctrl+Alt+L` (GNOME), `Alt+Shift+L` (KDE), `Ctrl+Alt+L` (Emacs), `Ctrl+Alt+L` (Sublime Text), `⌘ ⌥ L` (Sublime Text (macOS)), `Alt+Shift+F` (VSCode), `⌥ ⇧ F` (VSCode (macOS)) in this project, GoLand will optimize its imports automatically.

Procedure: Use the goimports -local grouping

When you use this grouping, GoLand puts all imports that begin with the specified string after third-party packages.

1. Open settings by pressing `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Comma` (VSCode), `⌘ Comma` (VSCode (macOS)) and navigate to `Editor | Code Style | Go`. .

2. Click the Imports tab.

3. From the Sorting type list, select goimports.

4. Select the Group checkbox.

5. Click the Imports starting with radio button and type the grouping prefix in the text field.

![The goimports -local grouping](https://resources.jetbrains.com/help/img/idea/2026.3/go_goimports_local_grouping.png)

Procedure: Optimize imports for all files in the folder

1. Right-click a folder in the Project tool window and select Optimize Imports.

2. In the Optimize Imports dialog, click Run.

