golang的vim工作环境配置

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 iMproved
filetype 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 plugin
syntax on
filetype 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,menu
autocmd BufWritePre *.go :Fmt

set showcmd
set ruler
" enable backspace
set backspace=indent,eol,start
set nu
set 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新增

" snipmate
Bundle "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

本文来自:开源中国博客

感谢作者:go-skyblue

查看原文:golang的vim工作环境配置

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。