1

It’s 2016 and we’ve finally got some good tools for Go development, such as IntelliJ IDEA or Visual Studio Code2.

But I’m a Sublime Text user for years, while still not ready to switch to other editor, tapping full potentials of this app is the optimal choice for me. Luckily I’ve found this: Golang tools, a fork of the abondoned plugin GoTools. Now, since the author doesn’t have time to update the doc, let me reorganize a brief introduction here.

Installing

  1. Sublime Text’s packages Install Package Control, then click ⌘+⇧+p & install below packages via Package Control: Install Package command.

    • Golang Build
    • Golang Tools Integration
    • FileDiffs
  2. Get Go dependencies

    • go get -u -v github.com/mdempsky/gocode3
    • go get -u -v github.com/golang/lint/golint
    • go get -u -v golang.org/x/tools/cmd/guru
    • go get -u -v golang.org/x/tools/cmd/goimports
    • go get -u -v golang.org/x/tools/cmd/gorename

Configuring user settings

  1. golangconfig(Menu → Preferences → Package Settings → Golang Config → Settings - User) These plugins for Go unify their settings via sublime-config, set once, run every where. :-)

     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
    
    {
        // Set environtment variables, use absolute paths.
        "PATH": "/Users/me/go/bin",
        "GOPATH": "/Users/me/go",
    
        // Format source files each time they're saved.
        "format_on_save": true,
    
        // A formatting backend (must be either 'gofmt', 'goimports' or 'both').
        // The 'both' option will first run 'goimports' then 'gofmt'
        "format_backend": "goimports",
    
        // Lint source files each time they're saved.
        "lint_on_save": true,
    
        // A lintting backend (must be either 'govet' or 'golint' or 'both').
        // The 'both' option will first run 'go vet' then 'golint'
        "lint_backend": "both",
    
        // Enable gocode autocompletion.
        "autocomplete": true,
    
        // Enable GoTools debugging output to the Sublime console.
        "debug_enabled": false
    }
    
  2. Key Bindings4

    Set some hotkeys to improve productivity.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    [
    	{ "keys": ["ctrl+."], "command": "auto_complete" },
    	{ "keys": ["ctrl+f"], "command": "gotools_goto_def" },
    	{ "keys": ["ctrl+r"], "command": "gotools_rename" },
    	{ "keys": ["ctrl+d"], "command": "gotools_doc" },
    	{ "keys": ["ctrl+g"], "command": "gotools_guru" },
    	{ "keys": ["ctrl+["], "command": "jump_back"},
    	{ "keys": ["ctrl+]"], "command": "jump_forward"},
    ]
    

    5

  1. mousemap6 Go to a definition using ⌃+Left Click
    1
    2
    3
    4
    5
    
    [
    	{
    		"button": "button1", "count": 1, "modifiers": ["ctrl"], "command": "gotools_goto_def"
    	},
    ]
    
  1. FileDiffs on right menu It’s the best diff plugin for now, I’m using Beyond Compare Pro as a companion, great pair.
    1
    2
    3
    4
    5
    6
    
    {
      // bcomp (Beyond Compare)
      // Install Beyond Compare Command Line Tools:
      // Beyond Compare > Install Command Line Tools
      "cmd": ["/usr/local/bin/bcomp", "$file1", "$file2"]
    }
    

Okay, now we built a lightweight yet complete Go IDE7, let’s rock!

UPDATE 2016.10.10: GoTools 1.0.9 supports the new serverless mode offered by mdempsky/gocode, you can enable it by adding "gocode_client_mode": true to golang-config settings.


  1. This picture is from official Go blog: Six years of Go ↩︎

  2. Francesc recently showed off how to Go with VS Code, have a look. ↩︎

  3. mdempsky/gocode is a code refined fork compared to the original repo, of course you can go get -u -v github.com/nsf/gocode instead. ↩︎

  4. ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap ↩︎

  5. You can configure more commands referring to gotools command definitions ↩︎

  6. ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-mousemap ↩︎

  7. I don’t debug so there’s no space for delve, log printing is good enough for me. ↩︎