In this post I’ll be going over how to install Sublime Text under Ubuntu and add in the plugins for GoSublime and GoToDoc which add in enhancements to Sublime for the Go programming language. First you’ll want to download Sublime itself: http://www.sublimetext.com/2
Once that’s done, open up a command line and unpack and install the files. In the below I’ll be assuming Sublime was downloaded into Downloads and I’ll be installing it under /opt/
cd Downloads
tar xvfj Sublime\ Text\ 2.0.1.tar.bz2
sudo mv "Sublime Text 2" /opt/Sublime_Text_2
Next add /opt/Sublime_Text_2 to your PATH in ~/.bashrc
echo "export PATH=\$PATH:/opt/Sublime_Text_2" >> ~/.bashrc
source ~/.bashrc
You’ll now be able to start up the software simply by running the command: sublime_text
The base Sublime install doesn’t include good support for Go. For that you’ll need a couple of external packages. To make these packages easier to install you’ll want to install something called Package Control. Package Control allows you to easily install packages from within Sublime.
Open up Sublime and press the Control key plus the ` key. This will open up the Sublime console. Copy and paste the below into it:
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'
Once that’s done you’ll be prompted to restart Sublime. Now that you have Package Control installed you can install GoSublime and GoToDoc. Fire up Sublime again and press Control Shift and P. This will bring up a text prompt at the top of the screen. Start typing in Package and choose the Package Control: Install Package from the drop down list.
Choosing that will prompt you for a package to install. Start typing in GoSublime and choose that.
GoSublime requires two other packages to handle syntax highlighting and other Sublime features. Press Control Shift and P again and start typing in “GoSublime: Install/Update MarGo and Gocode” and choose that.
Once that’s done we can install GoToDoc. Press Control Shift P again, start typing in Package, choose Package Control: Install Package and when prompted for the package to install start typing in GoToDoc.
For an example on how to use these plugins open up a simple “Hello World” hello.go file. Once that’s open in Sublime press and hold the Control key, then press comma and then R. That will run the code.
Most command for GoSublime use Control plus comma plus something else. You can see a list of what you can do by typing Control Shift P and start typing in GoSublime. That’ll give you a list of GoSublime functions and the hot key combinations to run them.
To use GoToDoc simply highlight a package name in the file(like fmt for example) and press Control Alt E. That’ll bring up a window in your web browser that goes to the documentation for that package. GoToDoc also has a Control Alt L function, but that conflicts with Ubuntu’s screen locking. So if you want that functionality(read more on it on the GoToDoc page) you’ll either need to remap it or remap Ubuntu’s screen locking.