Automatically Calling ‘go fmt’ from IntelliJ


There are currently several mature development environments built for the Go programming language. Some examples include vim-go for Vim and go-plus for Atom. Another entry that shows a lot of promise (but I hesitate to call mature) is the Go language plugin for IntelliJ.

Initially launched as GoIde, the implementation has since migrated to a plugin for the IntelliJ IDE rather than a stand-alone IDE. It has gone through several development cycles and at least one major rewrite but is finally starting to show real promise in matching the features found standard in other Go environments.

One feature found in other environments but currently not found stock in the Go language plugin is the automatic formatting of code (using go fmt) when changes are saved. However, this feature can be achieved with another IntelliJ plugin and a few project-specific settings.

Install File Watchers Plugin

Launch IntelliJ

  • Open the Preferences dialog
  • Click on the Plugins entry
  • Click Browse Repositories
  • Search for File Watchers
  • Click Install plugin
  • Click Restart IntelliJ IDEA

Setup ‘go fmt’ File Watcher

  • Open your Go project in IntelliJ
  • Open the Preferences dialog
  • Expand the Tools entry and click the File Watchers entry
  • Click the [+] button followed by the <custom> entry
  • Enter the following settings for the new File Watcher:

    Note that Immediate file synchronization should be unchecked otherwise you will get prompted by IntelliJ about outside changes to your files while editing source code.
  • Click OK


With the above changes in place IntelliJ behaves similarly to other popular Go environments for editors such as Vim and Atom. When you save your changes to any Go files ‘go fmt’ will be run automatically and the editor updated to reflect those changes.