這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
https://code.google.com/p/go/source/browse/misc/vim/readme.txt
如果遇到本地編譯問題,可以使用http://gobuild.io搞定
基礎工具安裝
- 安裝goimports
go get github.com/bradfitz/goimports
- 安裝gocode
go get github.com/nsf/gocode
- 安裝godef
go get code.google.com/p/rog-go/exp/cmd/godef
- 安裝vim(這個不講了,需要高版本的)
vundle安裝和配置
安裝vundle,這是一個管理vim外掛程式的外掛程式。很強大。
安裝方法我直接從github頁面上拷貝了
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
然後修改vimrc
set nocompatible " be iMprovedfiletype off " required!set rtp+=~/.vim/bundle/vundle/call vundle#rc()" let Vundle manage Vundle" required! Bundle 'gmarik/vundle'Bundle 'cespare/vim-golang' Bundle 'Blackrush/vim-gocode'" Bundle 'Valloric/YouCompleteMe'" ... other pluginsyntax onfiletype plugin indent on " required!"" Brief help" :BundleList - list configured bundles" :BundleInstall(!) - install (update) bundles" :BundleSearch(!) foo - search (or refresh cache first) for foo" :BundleClean(!) - confirm (or auto-approve) removal of unused bundles"" see :h vundle for more details or wiki for FAQ" NOTE: comments after Bundle commands are not allowed."set omnifunc=syntaxcomplete#Complete set completeopt=longest,menuautocmd BufWritePre *.go :Fmtset showcmdset ruler" enable backspaceset backspace=indent,eol,startset nuset mouse=
開啟vim,命令模式下執行:BunduleInstall
如果發現自動補全不好使,再來一步
cd $GOPATH/src/github.com/nsf/gocode && vim/update.sh
下面的忽略,驗證了下,會跟其他外掛程式有衝突
安裝YCM(主要是youcompleteme需要) cd ~/.vim/bundle/YouCompleteMe && ./install.sh
強化續(安裝snippets)
參考來源https://github.com/garbas/vim-snipmate
vimrc新增
" snipmateBundle "MarcWeber/vim-addon-mw-utils"Bundle "tomtom/tlib_vim"Bundle "garbas/vim-snipmate"" Optional:Bundle "honza/vim-snippets"
開啟vim,運行一遍 :BundleInstall
把裡面的記住就ok了。.vim/bundle/vim-snippets/snippets/go.snippets