How to enable go fmt on save in GoLand IDE
One thing I miss when switching from VS Code to GoLand is the ability to auto-format the code with go fmt
when saving the files.
You need to navigate to Tools > Go Tools > Go Fmt Project
to run it, or use the keyboard shortcut which is ⌥⇧⌘P. Still, this is something that you can easily forget to run every single time.
Luckily, GoLand have built in file watchers that you can use to run go fmt
every time there’s a file changes.
Here’s how;
- Go to
Preferences > Tools > File Watchers
- Click on the
Add
button and choosego fmt
- Click on the
OK
button to enable it
That’s it. Now when you saved your code, the file watchers will detect this changes and run go fmt
. You can even use file watchers to run other go tools like goimports
, go vet
or anything else that you think is helpful to you.