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