I use IntelliJ with the Golang plugin. Is it possible to configure the IDE to execute gofmt on file save?
Of course you can.
File Type
: Go
, Program
: the abosolute path of gofmt
, Arguments
: -w $FilePath$
OK
Gogland EAP 16 deprecated the On Save actions and replaced them with the File Watchers plugin .
If you have previously configured On Save actions, the IDE will prompt you to install the plugin and configure everything automatically. If you want to set it up from scratch yourself, check if you have File Watchers plugin and if not install it.
Enable gofmt:
Settings | Tools | File Watchers
Settings | Tools | File Watchers
Settings | Tools | File Watchers
. +
button and select go fmt
. You can do the same for goimports
and gometalinter
.
Updated:
For new versions of the Goland:
File->Settings->Tools->File Watchers
+
button and choose go fmt
Ok
Done :)
September 2021 Update.
If you are using GoLand with the 2021.2 version and higher (July 2021), there are a few options to enable gofmt on save besides File Watchers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.