Skip to content

Latest commit

 

History

History
107 lines (72 loc) · 4.07 KB

Setting_up_Sublime_properly.md

File metadata and controls

107 lines (72 loc) · 4.07 KB

Sublime for Go (golang), setup properly

This setup assumes C:\GoPath as your GOPATH. Changes any occurrences of this string into your GOPATH if you chose otherwise.

Setup environment variables:

  • Hit Windows+S, type in environment variables and start Edit the system environment variables.

  • Go to the Advanced tab, click the Environment variables (lower part of the window).

  • Under System variables:

    • set GOPATH to value C:\GoPath.
    • modify Path and append the value ;C:\GoPath\bin (separate the previous path with the ;)
    • set GOROOT to value C:\Go.
  • If you're going to use Git Bash, dump this in your ~/.profile (%USERPROFILE%/.profile under Windows). Both Mac OS X and Windows should work with that configuration:

export GOPATH=/c/GoPath
export PATH=/c/GoPath/bin:$PATH

Install Sublime Text 3.

Make sure you have Package Control installed.

Install Sublime plugins:

  • Hit Control+Shift+P (opens the Palette) and type in: install pack.. you should see Package Control: Install Package in the list. If you don't see that, install Package Control above.

  • If Package Control: Install Package is shown, hit <Enter> to pop the next box. Type in GoSublime and hit enter. It will install GoSublime

  • Hit Control+Shift+P, type in package install, hit <Enter> and type in GoGuru. Hit <Enter> again to install GoGuru.

  • Hit Control+Shift+P, type in package install, hit <Enter> and type in Godef. Hit <Enter> again to install Godef.

  • Hit Control+Shift+P, type in package install, hit <Enter> and type in SublimeLinter. Hit <Enter> again to install SublimeLinter 3.

  • Hit Control+Shift+P, type in package install, hit <Enter> and type in SublimeLinter golint. Hit <Enter> again to install SublimeLinter-contrib-golint.

  • Hit Control+Shift+P, type in package install, hit <Enter> and type in SublimeLinter gotype. Hit <Enter> again to install SublimeLinter-contrib-gotype. WARN: gotype currently blocks other linters, so you can either not install it, or disable it through the SublimeLinter menu.

  • Hit Control+Shift+P, type in package install, hit <Enter> and type in SublimeLinter govet. Hit <Enter> again to install SublimeLinter-contrib-govet.

Install some go command line tools:

  • On the command line, run:
go get -u -v github.com/rogpeppe/godef
go get -u -v golang.org/x/tools/cmd/guru
go get -v golang.org/x/tools/cmd/goimports
go get -u -v github.com/golang/lint/golint
go get -u -v golang.org/x/tools/cmd/gotype

(GoCode is integrated into GoSublime.. won't use an external version)

Configuring Sublime Text 3's plugins:

  • Open menu Preferences -> Package Settings -> GoSublime -> Settings - User and drop this in there:
{
    "fmt_cmd": ["goimports"]
}
  • Default bindings for GoGuru:
[{ "keys": ["ctrl+shift+g"], "command": "go_guru"}]
  • Default Go to definition with GoSublime:
["keys": ["ctrl+.", "ctrl+g"], "command": "gs_doc",...}]
  • golint and gotype are enabled automatically, check the Palette under SublimeLinter for more options. One notable function is SublimeLinter: Show all errors.. discover the keyboard shortcut in the Palette and memorize it.

Restart Sublime Text 3

If you have any issues, please open an issue on this repo.. I want that recipe to be flawless to onboard new Go developers on Sublime.

On Mac, you might have to restart your session, so that the ~/.profile changes are propagated to your running session. Otherwise, try starting Sublime from a terminal which has the GOPATH vars set.