Go Formatter formats Go code using goimports
or gofmt
.
There are three ways to run Go Formatter:
- On save: When a Go file is saved, it will automatically be formatted
- Menu item: Select the Editor → Format Go code menu item
- Command palette: Open the command palette and type
Format Go code
Using goimports
To use goimports
, it must be installed and visible in your environment (e.g., on your PATH
variable). goimports
can be installed with this shell command:
$ go install golang.org/x/tools/cmd/goimports@latest
Using gofmt
To use gofmt
:
- Uncheck the
"Use goimports if available"
extension preference - Ensure
gofmt
is installed (included with the official Go installer) and visible in your environment (e.g., on yourPATH
variable)
If Go Formatter fails to run, error messages will be shown as a Nova notification. If you run into an issue that you think Go Formatter should handle, please submit a bug report.
Go Formatter at Nova's Extension Library
Or, install using Nova by selecting Extensions → Extension Library..., searching for Go Formatter, and clicking the Install button.