在GoLang中保存运行“ goimports”

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

Adjusted due to new version of Goland:

The setting has meanwhile moved to the File Watchers. Here you can add a new file watcher at the bottom and select goimports from the list.

enter image description here

Original:

Are you looking for this setting?

enter image description here

Edit:

Setting this to go imports will do both:

  • code formatting
  • updating imports

"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.

P.S. Might not be the right place but I have less then 50 rep so I cannot comment :/