In Sublime Text 3, with plugins GoSublime
and GoImports
installed.
I'm having trouble having goimports
run on my file automatically everytime I save.
Here's what I tried :
My GoSublime settings are set to :
{
"env": {"GOPATH": "/home/nicolas/.go", "PATH": "$GOPATH/bin:$PATH" },
//"fmt_cmd": ["goimports"]
}
When I save with these settings, the code gets formatted but imports are not added. Nothing surprising so far.
If I hit ctrl+shift+P then GoImports, imports get added as expected.
Now my problem is, when I uncomment that previous line to have these settings :
{
"env": {"GOPATH": "/home/nicolas/.go", "PATH": "$GOPATH/bin:$PATH" },
"fmt_cmd": ["goimports"]
}
Not only does it not add the imports, but no other formatting gets done anymore.
Any idea where I went wrong ?
I'm using Linux (Ubuntu).
答案 0 :(得分:9)
{"fmt_cmd": ["goimports"]}
答案 1 :(得分:3)
所以,我错了:
我使用Package control > Install package > GoImports
从Sublime内部安装了GoImports。它将它安装在Sublime Packages文件夹中,该文件夹不在我的$PATH
我应该做些什么呢?
使用命令go get -u golang.org/x/tools/cmd/goimports
安装它。这将把它安装在你的$ GOPATH中(并且$ GOPATH / bin应该在你的$ PATH上)。
答案 2 :(得分:0)
ctrl+. , ctrl+x
打开margo.go
文件。
然后取消注释golang.GoFmt和golang.GoImports之一。重新启动崇高文字,然后重试。
// golang.GoFmt,
// or
// golang.GoImports,
我使用ubuntu + sublime text 3207 + Go-1.10 + Gosublime + Goimports-release-1.10
。它在我取消注释golang.GoImports后就可以使用。