<html><head><link rel="canonical" href="https://www.jetbrains.com/help/idea/integration-with-go-tools.html.md/" data-react-helmet="true"/></head><body># Go tools

IntelliJ&nbsp;IDEA integrates essential Go tools to help you write, format, analyze, and generate code more efficiently. This topic shows you how to use the most popular Go tools inside the IDE.

## gofmt

IntelliJ&nbsp;IDEA includes built-in import management and a code formatter. Imports are handled on the fly. To customize how imports are processed, 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+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) and navigate to `Languages &amp; Frameworks | Go | Imports`.

To reformat code, 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` (NetBeans), `Ctrl+Alt+Enter` (Visual Studio), `⌘ ⌥ ⏎` (Visual Studio (macOS)), `Ctrl+Alt+L` (Eclipse), `⌘ ⇧ F` (Eclipse (macOS)). Unlike `gofmt`, the IntelliJ&nbsp;IDEA formatter works with incomplete or syntactically incorrect code and can be applied to selected blocks. It also supports advanced formatting options such as inserting semicolons automatically, wrapping parameters, and more.

To run both formatters at once, enable the On Reformat Code action option under `Editor | Code Style | Go` on the Other tab.

You can also enable Reformat code in Actions on Save. This option is enabled by default. When you press `Ctrl+S` (Windows), `⌘ S` (macOS), `⌘ S` (IntelliJ IDEA Classic (macOS)), `⌘ S` (macOS System Shortcuts), `Ctrl+S` (XWin), `Ctrl+S` (GNOME), `Ctrl+S` (KDE), `Ctrl+X, Ctrl+S` (Emacs), `Ctrl+S` (Sublime Text), `⌘ S` (Sublime Text (macOS)), `Ctrl+S` (NetBeans), `Ctrl+Shift+S` (Visual Studio), `⌘ ⇧ S` (Visual Studio (macOS)), `Ctrl+S` (Eclipse), `⌘ S` (Eclipse (macOS)), the IDE runs both the built-in formatter and `gofmt`.

Use `gofmt` to format Go source code in the current file or across the whole project.

Procedure:

* To format code in the currently opened file, navigate to `Tools | Go Tools | Go Fmt File`.

* To format all code in the project, navigate to `Tools | Go Tools | Go Fmt Project`.

* To format code before committing changes to VCS, select the Go fmt checkbox in the Commit dialog. For more information, refer to [Commit and push changes to Git repository](commit-and-push-changes.html).

&gt; **Tip:**
&gt; To learn more, refer to [Command gofmt at pkg.go.dev](https://pkg.go.dev/cmd/gofmt).

## goimports

IntelliJ&nbsp;IDEA includes built-in import management and a code formatter. Imports are handled on the fly. To customize how imports are processed, 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+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) and navigate to `Languages &amp; Frameworks | Go | Imports`.

Use `goimports` to automatically add missing and remove unused imports.

Procedure:

* To apply `goimports`, navigate to `Tools | Go Tools | Goimports File`.

If `goimports` is not available in your project, click the `go install goimports` link in the notification. Alternatively, open the Terminal tool window (`View | Tool Windows | Terminal`) and run:

```
go install golang.org/x/tools/cmd/goimports@latest
```

&gt; **Tip:**
&gt; `goimports` also formats code in the same way as `gofmt`. For more details, see [Command goimports at pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/cmd/goimports).

## go generate

Use the `go generate` command and the `//go:generate` directive to run code generation tools.

Procedure:

1. Add a directive to your code:

```
//go:generate command arguments
```

For example: `//go:generate stringer -type=Pill`

2. Run `go generate` from the IDE:

* `Tools | Go Tools | Go Generate File`

* Or use the gutter icon ![Run icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.execute.svg) and select Go Generate

&gt; **Tip:**
&gt; For more details, refer to [Generate Go files by
&gt; processing source at pkg.go.dev](https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source) and [Generating code at go.dev](https://go.dev/blog/generate).

## go vet

Use `go vet` to identify possible bugs and suspicious constructs in Go source files.

Procedure:

* To run `go vet`, navigate to `Tools | Go Tools | Go Vet File`. The output will appear in the Terminal tool window.

&gt; **Tip:**
&gt; To learn more, refer to [Command vet at pkg.go.dev](https://pkg.go.dev/cmd/vet).

</body></html>