My Go courses are discounted for the next few weeks to help out anyone who may need or want access to them. I'm also going to try to help out anyone who can't afford a course, and I will be writing posts about working from home over the next week in an attempt to help anyone new to WFH. Read more here .

Add goimports to Sublime Text 3

This should workin pretty much any version of Sublime Text, but I have only tested it in Sublime Text 3.

I no longer use Sublime Text in my day to day Go development, and I instead use Atom. I’m hoping to eventually come back to Sublime Text, and I have toyed around with building a Go plugin for ST3, but as of Jan, 2018 Atom simply has better Go support with the go-plus plugin.

1. Install goimports

First off, install goimports in your terminal:

go get golang.org/x/tools/cmd/goimports

2. Install GoSublime

Next we need to install GoSublime in Sublime Text. Hit cmd + shift + p then type Install Package and select the install package option, then type GoSublime and select this package.

You may already have the package. An easy way to check is to hit cmd + shift + p and type Remove Package then look for it, and hit esc if you see it.

3. Set Up GoSublime

Next up we need to set up GoSublime to use goimports. To do this, you first want to open up your user preferences for GoSublime. You can do this via the menu (Sublime Text > Package Settings > GoSublime > Settings - User) or via the shortcut ( cmd + . then cmd + 5 ).

User settings, not default settings Make sure you use the user settings. Default settings can be overwritten with a package update, but user settings will be preserved.

Once this file is opened up, you need to add the line "fmt_cmd": [ "goimports" ] to the file. If your file has nothing else in it, the final version should look like this:

{ "fmt_cmd" : [ "goimports" ] }

If you have something else in it, simply add this line to the file and be sure to add a comma on the line before it if you need to.

3. Test it out

Go open up a go file, add some unnecessary packages, and hit save ( cmd + s ). The imports should be cleaned up!