I recently adopted JetBrains IntelliJ IDEA IDE with the rapidly-improving Go plugin for working on Go code (of course using IdeaVim!). I’ll post more about using IntelliJ as an IDE for Go in future (it recently grew support for debugging using Delve).

One of the things the plugin does not set up by default is running gofmt (or goimports) upon saving a file - behaviour I had previously had in Macvim. Restoring this turns out to be reasonably straightforward, with the help of a JetBrains plugin for IntelliJ named “File Watchers”. Having installed this, set the configuration up like this screenshot:

File Watcher Configuration

Now, whenver you save any .go file, the goimports tool will automatically fix any unused or missing imports, and format your code for you.