Go Code Formatter: Re-indent with Tabs (gofmt-Style Layout)
Fixes indentation, blank lines and optionally line breaks in Go code without sending it anywhere.
Use the tool
Why this tool exists
Messy indentation hides the structure of Go code, and minified or copy-pasted code is worse. A re-indenter gives you the block layout back quickly.
The tool reads your code with a small scanner that knows strings, comments and raw literals, so braces inside them are ignored. It then sets the indent from bracket depth and, if you ask, puts a line break after braces and semicolons. It is not gofmt.
How to use it
- Paste Go code.
- Keep tabs or choose spaces.
- Optionally break one-line code.
- Run gofmt locally for the final check.
Frequently asked questions
Is this the same as gofmt?
No. gofmt also aligns comments, struct fields and key-value pairs and normalises spacing. This tool fixes block indentation and blank lines. On the Go standard library, re-indenting files with all indentation stripped restored 166 of 187 files byte for byte; indentation of already-formatted files was kept in 202 of 208.
Will it change what my code does?
It only changes whitespace outside strings, comments and raw literals. Test results: the non-whitespace text was unchanged on all test files, and re-running the tool gave the same output. Review the diff anyway.
Why not wrap long lines?
Wrapping needs a full parser. This tool does not have one.
Is my input sent anywhere?
No. Everything runs in your browser and nothing is uploaded.