Last Updated: February 25, 2016
·
10.3K
· mattyw

Always run gofmt in vim

If you write go it's important to run gofmt before sharing it with others. If you're using vim add this to your .vimrc

au BufWritePost *.go !gofmt -w %

It will run gofmt on your file after you save it, but it doesn't refresh the buffer so you won't see your code suddenly change while your coding (if you want to refresh just do :e)

2 Responses
Add your response

The default Vim plugin (that comes with the Go source) adds a :Fmt function that will do the same to the current buffer.

over 1 year ago ·