gofmt
go.dev
- Free plan
- Windows
- macOS
- Linux
What gofmt is
gofmt is the Go source formatter included in Go installations, available on Linux, macOS, and Windows. It formats Go programs with tabs for indentation and blanks for alignment. Without a path it reads standard input; when given a directory, it recursively processes .go files while skipping files that begin with a period. By default, it prints reformatted source to standard output. Its flags can display diffs, list files with formatting differences, apply rewrite rules, simplify code, and report all errors. The rewrite option uses patterns and replacements that are valid Go expressions. gofmt can also reshape Go documentation comments into canonical paragraphs, lists, headings, links, and code blocks. The Go project documents integrations for Vim, Emacs, Eclipse, and Sublime Text, along with Git pre-commit hooks and Mercurial. Since Go 1.18, the formatter reads and formats input files concurrently, with memory limited in proportion to GOMAXPROCS. The executable is equivalent to go fmt. Go is distributed under a BSD-style open-source license.
Who it suits
Go developers who want a standard formatter for source files and documentation comments. Its documented editor integrations and hooks may suit users who want formatting in an existing workflow.
Good to know, and what to watch
- Included in Go installations and free to use.
- Formats .go files recursively when given a directory.
- Can show diffs, list changed files, or simplify code.
- Documented integrations include editors and version-control hooks.
- Formats Go programs only.
- Directory processing skips files beginning with a period.
- Default output goes to standard output rather than applying changes.
Plans
Every plan and pricegofmt
Free plan
The verdict
gofmt provides a focused way to format Go source, with options for inspecting or transforming files and comments. It is useful for Go workflows, but its scope is Go formatting rather than general-purpose code formatting.
What the maker publishes
- Comment formatting
- Gofmt reformats Go documentation comments into canonical paragraphs, lists, headings, links, and code blocks. source
- Distribution
- The Go installation process installs an executable called gofmt, equivalent to go fmt. source
- Editor integrations
- The Go project documents gofmt integrations for Vim, Emacs, Eclipse, Sublime Text, Git pre-commit hooks, and Mercurial. source
- Formatting options
- Its flags include displaying diffs, listing files with formatting differences, applying rewrite rules, simplifying code, and reporting all errors. source
- Input handling
- Without an explicit path, gofmt processes standard input; with a directory, it recursively processes .go files while ignoring files beginning with a period. source
- License
- Go is an open source project distributed under a BSD-style license. source
- Output
- By default, gofmt prints reformatted sources to standard output. source
- Performance
- Since Go 1.18, gofmt reads and formats input files concurrently with memory limited proportionally to GOMAXPROCS. source
- Platforms
- The Go compiler toolchain can target AIX, Android, DragonFly BSD, FreeBSD, Illumos, Linux, macOS/iOS, NetBSD, OpenBSD, Plan 9, Solaris, and Windows. source
- Purpose
- Gofmt automatically formats Go programs using tabs for indentation and blanks for alignment. source
- Security
- The Go project issues security fixes to the two most recent major Go releases and provides a security policy for reporting vulnerabilities. source
- Source transformation
- The -r flag applies rewrite rules whose patterns and replacements are valid Go expressions. source
- Support
- Questions about using Go or announcements relevant to Go users should be sent to the golang-nuts mailing list. source
Checked against the maker's pages on 1 Oct 2026.