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).
$GOPATH/bin is in your $PATH (Windows: %GOPATH%\bin goes
in your %PATH%).go get -u golang.org/x/tools/cmd/goimports (you may have to
install mercurial).config/preference file (Mac: ⌘. ⌘5 Windows:
Ctrl+. Ctrl+5). Make sure you keep the command button down for the
whole shortcut sequence.{"fmt_cmd": ["goimports"]}
Source
So, where I went wrong :
I installed GoImports from inside Sublime using Package control > Install package > GoImports. That installed it in the Sublime Packages folder, which was not on my $PATH
What I should have done instead :
Install it using the command go get -u golang.org/x/tools/cmd/goimports. This will install it in your $GOPATH (and $GOPATH/bin should be on your $PATH).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With