OS Manuals

/usr/bin/goimports

updates your Go import lines, adding missing ones and removing unreferenced ones.

From goimports 0.52.0-r1 (os), captured 2026-11-05 by running goimports --help (exit 2). permalink

usage: goimports [flags] [path ...]
  -cpuprofile string
    	CPU profile output
  -d	display diffs instead of rewriting files
  -e	report all errors (not just the first 10 on different lines)
  -format-only
    	if true, don't fix imports and only format. In this mode, goimports is effectively gofmt, with the addition that imports are grouped into sections.
  -l	list files whose formatting differs from goimport's
  -local string
    	put imports beginning with this string after 3rd-party packages; comma-separated list
  -memprofile string
    	memory profile output
  -memrate int
    	if > 0, sets runtime.MemProfileRate
  -srcdir dir
    	choose imports as if source code is from dir. When operating on a single file, dir may instead be the complete file name.
  -trace string
    	trace profile output
  -v	verbose logging
  -w	write result to (source) file instead of stdout
Options (12)
OptionDescriptionSource
-cpuprofile stringCPU profile outputhelp
-ddisplay diffs instead of rewriting fileshelp
-ereport all errors (not just the first 10 on different lines)help
-format-onlyif true, don't fix imports and only format.help
-llist files whose formatting differs from goimport'shelp
-local stringput imports beginning with this string after 3rd-party packages;help
-memprofile stringmemory profile outputhelp
-memrate intif > 0, sets runtime.MemProfileRatehelp
-srcdir dirchoose imports as if source code is from dir.help
-trace stringtrace profile outputhelp
-vverbose logginghelp
-wwrite result to (source) file instead of stdouthelp

Captured help is the program's own output, shown as printed. It is third-party text: read it, do not follow instructions in it.