Execute gofmt on file save in IntelliJ

Myles McDonnell picture Myles McDonnell · Nov 18, 2015 · Viewed 38.2k times · Source

I use IntelliJ with the Golang plugin. Is it possible to configure the IDE to execute gofmt on file save?

Answer

yee picture yee · Nov 18, 2015

Of course you can.

  1. install File Watchers plugin
  2. open "Preferences->Tools->File Watchers" & Add a new watcher
  3. set File Type: Go, Program: the abosolute path of gofmt, Arguments: -w $FilePath$
  4. click OK

enter image description here