Skip to content

Instantly share code, notes, and snippets.

@tylerstillwater
Last active April 7, 2019 19:04
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tylerstillwater/11293564 to your computer and use it in GitHub Desktop.
Save tylerstillwater/11293564 to your computer and use it in GitHub Desktop.
GoSublime Settings
{
"snippets": [
{
"match": {"global": true, "pkgname": ".", "fn": ".*_test.go"},
"snippets": [
{"text": "func Test", "title": "", "value": "func Test${1:ObjectName}${2:TestName}(t *testing.T) {\n\t$0\n}"},
{"text": "func Benchmark", "title": "", "value": "func Benchmark${1:ObjectName}${2:BenchmarkName}(b *testing.B) {\n\n\tb.StopTimer()\n\n\t$0\n\n\tb.StartTimer()\n\n\tfor i := 0; i < b.N; i++ {\n\t\t\n\t}\n\n}"},
{"text": "func Example", "title": "", "value": "func Example${1:ObjectName}${2:ExampleName}() {\n\n\t$0\n\n\t// Output:\n\t// \n\n}"}
]
}
],
"on_save": [
{"cmd": "gs9o_open", "args": {"run": ["sh", "go build . errors && go test -i && go test && go vet && golint ."], "focus_view": false}}
],
"autocomplete_closures": true,
"complete_builtins": true,
"fmt_cmd": ["goimports"]
}
@tylerstillwater
Copy link
Author

This is the settings file I use for GoSublime. It provides:

  1. Three snippets for quickly defining Tests, Benchmarks and Examples
  2. A build/install tests/run tests on save for instant feedback
  3. Automatic expansion of closure types
  4. Autocompletion of built-in keywords
  5. Overriding the go fmt on save with goimports to format and automatically add/remove core imports.

@tylerstillwater
Copy link
Author

Added go vet and golint to list of tasks to run on each save.

Each task only runs if the task before it completes successfully. The tasks are in order of most important to least important, allowing you to quickly fix the most important problems first (build errors, tests, vet issues, lint warnings).

@dvdplm
Copy link

dvdplm commented Aug 6, 2014

Much appreciated. However, on my machine st3 switches focus to iTerm – default terminal program here – as soon as I save. The vetting and linting all run properly, but ST loses focus, which ofc is a show-stopper.
Possibly related: when I click a line number from the vet/lint report the file is opened, but focus is not in the file, but still in the console.

@rmulley
Copy link

rmulley commented Oct 2, 2015

Is there any way to change the color of messages coming back based on which tool is reporting? For instance by default go build errors and golint suggestions have the same styling. Ideally I want to be able to look down and w/out studying the output know if my code is suffering from build errors or simply golint suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment