Recently I found I like Sublime Text more because of happy coding flow in Golang here.
Very much!!!
As usual, picture first!
1. Setup Go Env
- Install Go Env.
- install from official site: https://golang.org/doc/install
- install by homebrew in Mac: https://mnafian.github.io/2016/10/26/Install-Go-by-Homebrew-OSX.html
- Make sure you have
GOROOT
andGOPATH
well-setup. - You should know basic ideas of go package mgmt, like:
{src,pkg,bin}
under $GOPATHgo get
to downloadgo build
to buildgo install
to install- etc …
2. Setup Sublime Text 3
- Install Sublime Text3
- Install Sublime Text3 Package Control
- Install GoSublime Package from
Install Package
, typegosublime
there.
Yes, you’re all done!
3. AutoCompletion in GoSublime
By default, GoSublime will make auto completion when using golang standard library code. If you want to make your own code able to be auto completed, you need to put compiled artifacts under pkg
directory of your $GOPATH
.
How to do that? Using go get ./...
!
3.1. Configuration in GoSublime
Using super+..
(here we means hold super key and double hit dot key), go to User Settings
, will open golang user settings config file.
Use the config like below, we use gs_comp_lint
when on_save
event happens. Of course, in gs_comp_lint
, there is a list of commands, in which, we have go get ./...
as one of them.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35{
"env": {
"GOPAHT": "/Users/morganwu/Developer/workspace/go",
"GOROOT": "/usr/local/opt/go/libexec"
},
// enable comp-lint, this will effectively disable the live linter
"comp_lint_enabled": true,
// list of commands to run
"comp_lint_commands": [
// run `go get ./...` to install all current project's pkgs
{"cmd": ["go", "get", "./..."]},
// run `golint` on all files in the package
// "shell":true is required in order to run the command through your shell (to expand `*.go`)
// also see: the documentation for the `shell` setting in the default settings file ctrl+dot,ctrl+4
{"cmd": ["golint *.go"], "shell": true},
// run go vet on the package
// {"cmd": ["go", "vet"]},
// run `go install` on the package. GOBIN is set,
// so `main` packages shouldn't result in the installation of a binary
// {"cmd": ["go", "install"]},
],
"on_save": [
// run comp-lint when you save,
// naturally, you can also bind this command `gs_comp_lint`
// to a key binding if you want
{"cmd": "gs_comp_lint"}
]
}
4. Conclusion
- Use
go get ./...
to recursively download and install all packages of current project. - Customize
on_save
event commands by usingUser Settings
.
Ref: