×

IDMWORKS Blog

Automatically Calling ‘go fmt’ from IntelliJ


intellijidea.png

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


  • Conclusion
    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.

    Questions, comments or concerns? Feel free to reach out to us below, or email us at IDMWORKS to learn more about how you can protect your organization and customers.

    Tags: ,

    Leave a Reply

    Your email address will not be published. Required fields are marked *