github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/cmd/goimports/doc.go (about) 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 7 Command goimports updates your Go import lines, 8 adding missing ones and removing unreferenced ones. 9 10 $ go install github.com/powerman/golang-tools/cmd/goimports@latest 11 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. 15 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) 21 22 For vim, set "gofmt_command" to "goimports": 23 https://golang.org/change/39c724dd7f252 24 https://golang.org/wiki/IDEsAndTextEditorPlugins 25 etc 26 27 For GoSublime, follow the steps described here: 28 http://michaelwhatcott.com/gosublime-goimports/ 29 30 For other editors, you probably know what to do. 31 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. 39 40 File bugs or feature requests at: 41 42 https://golang.org/issues/new?title=x/tools/cmd/goimports:+ 43 44 Happy hacking! 45 46 */ 47 package main // import "github.com/powerman/golang-tools/cmd/goimports"