3 Command goimports updates your Go import lines,
4 adding missing ones and removing unreferenced ones.
6 $ go get golang.org/x/tools/cmd/goimports
8 In addition to fixing imports, goimports also formats
9 your code in the same style as gofmt so it can be used
10 as a replacement for your editor's gofmt-on-save hook.
12 For emacs, make sure you have the latest go-mode.el:
13 https://github.com/dominikh/go-mode.el
14 Then in your .emacs file:
15 (setq gofmt-command "goimports")
16 (add-hook 'before-save-hook 'gofmt-before-save)
18 For vim, set "gofmt_command" to "goimports":
19 https://golang.org/change/39c724dd7f252
20 https://golang.org/wiki/IDEsAndTextEditorPlugins
23 For GoSublime, follow the steps described here:
24 http://michaelwhatcott.com/gosublime-goimports/
26 For other editors, you probably know what to do.
28 To exclude directories in your $GOPATH from being scanned for Go
29 files, goimports respects a configuration file at
30 $GOPATH/src/.goimportsignore which may contain blank lines, comment
31 lines (beginning with '#'), or lines naming a directory relative to
32 the configuration file to ignore when scanning. No globbing or regex
33 patterns are allowed. Use the "-v" verbose flag to verify it's
34 working and see what goimports is doing.
36 File bugs or feature requests at:
38 https://golang.org/issues/new?title=x/tools/cmd/goimports:+
43 package main // import "golang.org/x/tools/cmd/goimports"