Add GoLang syntax highlighting for VIM

Solution 1:

UPDATE:

Go 1.4 Release Notes

Miscellany

The standard repository's top-level misc directory used to contain Go support for editors and IDEs: plugins, initialization scripts and so on. Maintaining these was becoming time-consuming and needed external help because many of the editors listed were not used by members of the core team. It also required us to make decisions about which plugin was best for a given editor, even for editors we do not use. The Go community at large is much better suited to managing this information. In Go 1.4, therefore, this support has been removed from the repository. Instead, there is a curated, informative list of what's available on a wiki page.


The standard Go distribution includes Go files for Vim in go/misc/vim/. This directory contains a readme.txt file which contains installation instructions.

readme.txt

Vim plugins for Go (http://golang.org)

To use all the Vim plugins, add these lines to your $HOME/.vimrc.

" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on

If you want to select fewer plugins, use the instructions in the rest of this file.

<<..SNIP..>>

Solution 2:

On Debian, I suppose it's the same on ubuntu, you just :

sudo apt-get install vim-gocomplete gocode vim-syntax-go
vim-addon-manager install go-syntax
vim-addon-manager install gocode

Solution 3:

you can just add these lines to your ~/.vimrc:

set rtp+=$GOROOT/misc/vim
filetype plugin indent on
syntax on

EDIT This assumes filetype plugin indent off before these lines (i.e. beginning of .vimrc file) and may cause problems if it's not. See @peterSO's answer below for the safer version.