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 19 screencasts and the first few chapters from the book.

You will also receive emails from me about Go coding techniques, upcoming courses (including FREE ones), and course discounts.

Avatar of Jon Calhoun
Written by
Jon Calhoun

Jon Calhoun is a full stack web developer who teaches about Go, web development, algorithms, and anything programming. If you haven't already, you should totally check out his Go courses.

Previously, Jon worked at several statups including co-founding EasyPost, a shipping API used by several fortune 500 companies. Prior to that Jon worked at Google, competed at world finals in programming competitions, and has been programming since he was a child.

Related articles

Spread the word

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

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 All Articles Mini-Series Progress Updates Tags About Me Go Courses

©2018 Jonathan Calhoun. All rights reserved.