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