Freedom251 › Code Formatting Tools
gofmt

What gofmt is
gofmt is a free command-line formatter for Go programs, included with Go installations as an executable equivalent to `go fmt`. It formats source with tabs for indentation and blanks for alignment. Without a path, it reads standard input; when given a directory, it recursively handles `.go` files while ignoring files whose names begin with a period. By default, it sends reformatted source to standard output. Its options 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 also formats Go documentation comments into canonical paragraphs, lists, headings, links, and code blocks. The Go project documents integrations for Vim, Emacs, Eclipse, and Sublime Text, as well as Git pre-commit hooks and Mercurial. Since Go 1.18, it reads and formats input files concurrently, with memory limited in proportion to GOMAXPROCS. It runs on Linux, macOS, and Windows and is distributed under a BSD-style license as part of the open-source Go project.
Who it suits
gofmt suits Go developers who want a consistent formatter in command-line workflows or documented editor and version-control integrations. It is available on Linux, macOS, and Windows.
What it does well
- Free executable included with Go installations.
- Can format directories recursively.
- Options include diffs, simplification, and rewrite rules.
- Documented editor and version-control integrations.
- Supports Linux, macOS, and Windows.
What to know first
- Formats Go programs only.
- Directory processing skips files beginning with a period.
- Default output goes to standard output.
Plans
| Plan | Billed and limits | Price |
|---|---|---|
| gofmt | included executable in Go installation · command-line use | Free |
As go.dev lists them, read 1 Oct 2026. The maker's own page has the final word.
Getting started
- Install Go to get the gofmt executable.
- Run gofmt without a path to process standard input, or provide a file or directory.
- Use a documented integration for Vim, Emacs, Eclipse, or Sublime Text if desired.
- Use a Git pre-commit hook or Mercurial integration if desired.
Verdict
gofmt provides a focused way to format Go source, with options for checking differences and applying transformations. Its documented integrations make it usable alongside several editors and version-control workflows.
Questions
How much does gofmt cost?
gofmt is free and is included in Go installations.
Which platforms does it support?
It is available on Linux, macOS, and Windows.
What language does gofmt format?
gofmt formats Go programs.
Is gofmt open source?
Yes. It is part of the open-source Go project, distributed under a BSD-style license.
Can gofmt work with editors or version-control workflows?
The Go project documents integrations for Vim, Emacs, Eclipse, and Sublime Text, as well as Git pre-commit hooks and Mercurial.
What happens when I give gofmt a directory?
It processes Go files recursively and ignores files whose names begin with a period.
Facts from gofmt's own pages
- Comment formatting
- Gofmt reformats Go documentation comments into canonical paragraphs, lists, headings, links, and code blocks. · go.dev, 1 Oct 2026
- Distribution
- The Go installation process installs an executable called gofmt, equivalent to go fmt. · go.dev, 1 Oct 2026
- Editor integrations
- The Go project documents gofmt integrations for Vim, Emacs, Eclipse, Sublime Text, Git pre-commit hooks, and Mercurial. · go.dev, 1 Oct 2026
- Formatting options
- Its flags include displaying diffs, listing files with formatting differences, applying rewrite rules, simplifying code, and reporting all errors. · go.dev, 1 Oct 2026
- 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. · go.dev, 1 Oct 2026
- License
- Go is an open source project distributed under a BSD-style license. · go.dev, 1 Oct 2026
- Output
- By default, gofmt prints reformatted sources to standard output. · go.dev, 1 Oct 2026
- Performance
- Since Go 1.18, gofmt reads and formats input files concurrently with memory limited proportionally to GOMAXPROCS. · go.dev, 1 Oct 2026
- Platforms
- The Go compiler toolchain can target AIX, Android, DragonFly BSD, FreeBSD, Illumos, Linux, macOS/iOS, NetBSD, OpenBSD, Plan 9, Solaris, and Windows. · go.dev, 1 Oct 2026
- Purpose
- Gofmt automatically formats Go programs using tabs for indentation and blanks for alignment. · go.dev, 1 Oct 2026
- Security
- The Go project issues security fixes to the two most recent major Go releases and provides a security policy for reporting vulnerabilities. · go.dev, 1 Oct 2026
- Source transformation
- The -r flag applies rewrite rules whose patterns and replacements are valid Go expressions. · go.dev, 1 Oct 2026
- Support
- Questions about using Go or announcements relevant to Go users should be sent to the golang-nuts mailing list. · go.dev, 1 Oct 2026
Where gofmt stands on Freedom251
- Code Formatting Tools#13 of 34