2015-08-06更新
简易配置
" Remember last position if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif endif filetype on Syntax on set showcmd set ruler " enable backspace set backspace=indent,eol,start set nu set mouse= set ts=4 sts=4 sw=4 set encoding=utf-8 " set expandtab " set completeopt=longest,menu autocmd Filetype python set ts=4 sts=4 expandtab autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd Filetype java setlocal omnifunc=javacomplete#Complete
https://code.google.com/p/go/source/browse/misc/vim/readme.txt
基础工具安装
- 安装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安装和配置
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
然后修改vimrc
set nocompatible " be iMproved,required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively,pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle,required Plugin 'gmarik/Vundle.vim' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo "Plugin 'tpope/vim-fugitive' " plugin from http://vim-scripts.org/vim/scripts.html "Plugin 'L9' " Git plugin not hosted on GitHub "Plugin 'git://git.wincent.com/command-t.git' " git repos on your local machine (i.e. when working on your own plugin) "Plugin 'file:///home/gmarik/path/to/plugin' " The sparkup vim script is in a subdirectory of this repo called vim. " Pass the path to set the runtimepath properly. "Plugin 'rstacruz/sparkup',{'rtp': 'vim/'} " Avoid a name conflict with L9 "Plugin 'user/L9',{'name': 'newL9'} " "Plugin 'gmarik/vundle' " ... other plugin "Plugin 'Valloric/YouCompleteMe' Plugin 'python.vim' Plugin 'cespare/vim-golang' Plugin 'Blackrush/vim-gocode' Plugin 'pylint.vim' " template Plugin 'pathogen.vim' Plugin 'aperezdc/vim-template' " snippets Plugin 'SirVer/ultisnips' Plugin 'honza/vim-snippets' let g:UltiSnipsExpandTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<c-b>" let g:UltiSnipsJumpBackwardTrigger="<c-z>" " If you want :UltiSnipsEdit to split your window. let g:UltiSnipsEditSplit="vertical" " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes,instead use: "filetype plugin on " " Brief help " :PluginList - list configured plugins " :PluginInstall(!) - install (update) plugins " :PluginSearch(!) foo - search (or refresh cache first) for foo " :PluginClean(!) - confirm (or auto-approve) removal of unused plugins " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line " " Remember last position if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif endif " "set omnifunc=Syntaxcomplete#Complete "set completeopt=longest,menu let g:gofmt_command = "goimports" autocmd BufWritePre *.go :Fmt Syntax on set showcmd set ruler " enable backspace set backspace=indent,menu autocmd Filetype python set ts=4 sts=4 expandtab autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd Filetype java setlocal omnifunc=javacomplete#Complete
开启vim,命令模式下执行:PluginInstall
如果发现自动补全不好使,再来一步
(cd $GOPATH/src/github.com/nsf/gocode && vim/update.sh)
下面的忽略,验证了下,会跟其他插件有冲突
snipets修改:.vim/bundle/vim-snippets/snippets/go.snippets