Gofmt is a Sublime Text 3 plugin that auto-formats Go code. Requires Sublime Text version 3124 or later. Simpler alternative to noonat/sublime-gofmt without error highlighting.
Deprecated in favor of https://github.com/mitranim/sublime-fmt which is more general.
This plugin is not on Package Control and requires manual installation.
Clone the repo:
git clone https://github.com/mitranim/sublime-gofmt.gitThen symlink it to your Sublime packages directory. Example for MacOS:
mv sublime-gofmt Gofmt
cd Gofmt
ln -sf "$(pwd)" "$HOME/Library/Application Support/Sublime Text 3/Packages/"To find the packages directory, use Sublime Text menu → Preferences → Browse Packages.
By default, Gofmt will autoformat files before saving. You can trigger it
manually with the Gofmt: Format Buffer command in the command palette.
I highly recommend installing goimports and using it instead of gofmt:
See Gofmt.sublime-settings for all available settings. To override them, open:
Preferences → Package Settings → Gofmt → Settings
Gofmt looks for settings in the following places:
"Gofmt"dict in general Sublime settings, possibly project-specificGofmt.sublime-settings, default or user-created
The general Sublime settings take priority. To override them on a per-project basis, create a "Gofmt" entry:
"Gofmt": {
"format_on_save": false
},In Sublime's command palette:
Gofmt: Format Buffer
To avoid potential conflicts, this plugin does not come with hotkeys. To hotkey
the format command, add something like this to your .sublime-keymap:
{
"keys": ["ctrl+super+k"],
"command": "gofmt_format_buffer",
"context": [{"key": "selector", "operator": "equal", "operand": "source.go"}]
}