- Make sure
$GOPATH/bin
is in your$PATH
(Windows:%GOPATH%\bin
goes in your%PATH%
). 【保证你的golang环境正常】 - Run
go get -u golang.org/x/tools/cmd/goimports
(you may have to install mercurial). 【通过go下载工具】 - Install Sublime Text and GoSublime (or make sure you’ve got the latest update if it’s already installed). 【安装了sublime text 和 Gosublime插件】
- Open the gosublime user config/preference file (Mac:
⌘. ⌘5
Windows:Ctrl+. Ctrl+5
). Make sure you keep the command button down for the whole shortcut sequence. 【进行配置】 - Make it look like this:
{ "fmt_cmd": ["goimports"] }
然后,你在保存的时候,如果漏掉了系统import的包,就会自动帮你import。
个人感觉,copy的代码更需要这个。自己新写的代码,一般都会记得包含,因为不import对应的包, Gosublime就没办法进行函数的提示了。
有疑问加站长微信联系(非本文作者)