Go comes pre-installed in Ubuntu 12.04. This means that some of the instructions on golang.org require a little bit of modification when you're running Ubuntu. The biggest thing to remember is that the Go packages live at /usr/lib/go.
If I've left anything out please add to the comments and I'll amend this entry until it's correct.
If I've left anything out please add to the comments and I'll amend this entry until it's correct.
Syntax Highlighting
This took me awhile to figure out but in the end the steps required to make syntax highlighting work for Go in Ubuntu 12.04 are easy.
Create some folders off of your home folder:
.vim
.vim/syntax
.vim/ftdetect
Then install "vim-syntax-go" b/c the files normally in "go/misc" files aren't part of the pre-installed Go version for 12.04. All of the instructions for non-Ubuntu installations make the assumption that "go/misc" files are present.
As the directions here specify:
"Place $GOROOT/misc/vim/syntax/go.vim in ~/.vim/syntax/" This is confusing because the go.vim file specified above isn't where the instructions say it is. You'll find go.vim at /usr/share/vim/addons/syntax (this is where the vim-syntax-go package put it). Just copy /usr/share/vim/addons/syntax/go.vim to $HOME/.vim/syntax/ and it should work.
And then put the following in ~/.vim/ftdetect/go.vim (create the go.vim file manually).
"au BufRead,BufNewFile *.go set filetype=go"
This has been enough for me to get syntax highlighting to work on two different machines.
AutoCompletion via the gocode daemon by nsf
This also took awhile to figure out but in the end it's easy to get running. Nsf's directions can be found here, they are very straightforward but you have to make allowances for the fact that Ubuntu's pre-installed Go packages are installed in /usr/lib/go. The difference between the normal install and the Ubuntu version for me was that when I ran "go env" to get the Go environment variables my $GOBIN path was blank. So I ran "export GOBIN=/usr/lib/go/bin" to set it and then "export PATH=$PATH:/usr/lib/go/bin" to make sure $GOBIN was in my $PATH because Vim would look for the gocode executable there. Next I ran "go get -u github.com/nsf/gocode" per nsf's instructions. Then, I went to /usr/share/go/src/pkg/github.com/nsf/gocode/vim" and ran "./update.bash". Finally I added to my .vimrc file "filetype plugin on". That was enough to make it work for me.
Also, I added this line to my $HOME/.profile file at the end:
"export PATH=$PATH:/usr/lib/go/bin"
This makes sure that /usr/lib/go/bin is part of my $PATH environment variable every time I login.
Also, I added this line to my $HOME/.profile file at the end:
"export PATH=$PATH:/usr/lib/go/bin"
This makes sure that /usr/lib/go/bin is part of my $PATH environment variable every time I login.