Running 'goimports' on save in GoLand

Viewed 18836

I'm using GoLand IDE to code in Go. When I save a file, I'd like that the unused imports disappear (like VS code)

I have enable "Optimize imports" in "Code" -> "Show reformat file dialog". But when I save the file, imports it's still present

3 Answers

"On Save" tab was removed in GogLand EAP 16.

In newer versions you have to go to Settings -> Tools -> File Watchers and add goimports there.

For those fighting with gofmt on Goland autosave (mat007 comment)

You can double click the item in file watchers to show an edit watcher menu.

Uncheck Auto-save edited files to trigger watcher and it should now only trigger on manual save:

enter image description here (Goland 2020.3)

Related