Sublime Text 3 can be a great editor for writing Go code - and with a few simple tweaks it can get better. One example of a simple workflow improvement to automate the running of
go fmt each time you save. This keeps your code neat and tidy, while also alerting you to any syntax errors.
Some things you'll need to get started:
- Go installed (with a GOPATH)
- Sublime Text Installed
1) Install Package Control
Firstly, we'll install Sublime's Package Control by going to their site: packagecontrol.io/installation. There's some code to copy and paste which should install it all for you. If you haven't used this plugin before it makes installing plugins within Sublime Text very easy.
2) Install Build
Within Sublime, if we now:
Ctrl + Shift + P
- Start typing and select ‘Package Control: Install Package’
- Install the sublime-build package by typing: ‘Golang Build’
We can manually build now by pressing
Ctrl + B, which will show a popup at the bottom to confirm it's run. But also, each time to hit
Ctrl + S to save, it will also format your code for you.