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.

1.Install goimports

First off, install goimports in your terminal:

go get

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).

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!

Learn Web Development with Go!

Sign up for my mailing list and I'll send you a FREE sample from my course - Web Development with Go. The sample includes three chapters from the book, and over 2.5 hours of screencasts.

You will also receive notifications when I release new articles, along with other freebies that I only share with my mailing list.

Avatar of Jon Calhoun
Written by
Jon Calhoun

Jon Calhoun is a full stack web developer who also teaches about Go, web development, algorithms, and anything programming related. He also consults for other companies who have development needs. (If you need some development work done, get in touch!)

Jon is a co-founder of EasyPost, a shipping API that many fortune 500 companies use to power their shipping infrastructure, and prior to founding EasyPost he worked at google as a software engineer.

Related articles

Spread the word

Did you find this page helpful? Let others know about it!

Vote on Hacker News

Sharing helps me continue to create both free and premium Go resources.

Want to discuss the article?

See something that is wrong, think this article could be improved, or just want to say thanks? I'd love to hear what you have to say!

You can reach me via email or via twitter.

Recent Articles Mini-Series Tags About Me Go Courses

©2018 Jonathan Calhoun. All rights reserved.