GoLang之再谈Gvim/Vim配置——使用Vundle安装vim-go

摘要:之前总结过在subl中使用GoLang,《GoLang及Sublime Text 2之Mac OS X 10.8.4开发环境安装 》。其实GoLang的安装包中已经包含了支持Vim的编写插件,配置方法很简单,可参考《GoLang之Gvim/Vim配置》。本文再讨论下使用Vundle如何在Vim中配置GoLang开发环境vim-go


根据Vundle的安装说明,首先安装Vundle:

$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

然后对.vimrc进行配置,将Vundle的相关配置置在最开始处,下面只显示关于Vundle的相关配置:

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. " -------------  
  2. " Vundle  
  3. " https://github.com/gmarik/Vundle.vim  
  4. " -------------  
  5.   
  6. set nocompatible              " be iMproved, required  
  7. filetype off                  " required  
  8.   
  9. " set the runtime path to include Vundle and initialize  
  10. set rtp+=~/.vim/bundle/Vundle.vim  
  11. call vundle#begin()  
  12. " alternatively, pass a path where Vundle should install plugins  
  13. "call vundle#begin('~/some/path/here')  
  14.   
  15. " let Vundle manage Vundle, required  
  16. Plugin 'gmarik/Vundle.vim'  
  17.   
  18. " The following are examples of different formats supported.  
  19. " Keep Plugin commands between vundle#begin/end.  
  20. " plugin on GitHub repo  
  21. ""Plugin 'tpope/vim-fugitive'  
  22. " plugin from http://vim-scripts.org/vim/scripts.html  
  23. ""Plugin 'L9'  
  24. " Git plugin not hosted on GitHub  
  25. ""Plugin 'git://git.wincent.com/command-t.git'  
  26. " git repos on your local machine (i.e. when working on your own plugin)  
  27. ""Plugin 'file:///home/gmarik/path/to/plugin'  
  28. " The sparkup vim script is in a subdirectory of this repo called vim.  
  29. " Pass the path to set the runtimepath properly.  
  30. ""Plugin 'rstacruz/sparkup', {'rtp''vim/'}  
  31. " Avoid a name conflict with L9  
  32. ""Plugin 'user/L9', {'name''newL9'}  
  33.   
  34. " Install Vim-go  
  35. Plugin 'fatih/vim-go'  
  36.   
  37. " All of your Plugins must be added before the following line  
  38. call vundle#end()            " required  
  39. filetype plugin indent on    " required  
  40. " To ignore plugin indent changes, instead use:  
  41. "filetype plugin on  
  42. "  
  43. " Brief help  
  44. " :PluginList       - lists configured plugins  
  45. " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate  
  46. " :PluginSearch foo - searches for foo; append `!` to refresh local cache  
  47. " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal  
  48. "  
  49. " see :h vundle for more details or wiki for FAQ  
  50. " Put your non-Plugin stuff after this line  

其中,配置中的 Plugin 'fatih/vim-go' 告诉Vundle我们想要安装vim-go这个插件,安装方法如下:

先用vim打开任意一个go源文件(假如之前并未配置过GoLang开发环境,确保~/.vim/syntax下没有使用vim.go,打开go的源文件后不会有对应的语法显示),例如,hello.go。然后使用命令 :PluginInstall 就可以安装vim-go了,安装成功后会在最下面显示Done的字样。



安装好插件后,再次用vim打开hello.go文件就可以看到vim-go插件已经生效了。




接下来的工作:(install necessary Go tools)

Please be sure all necessary binaries are installed (such as gocode,godef,goimports, etc..). You can easily install them with the included:GoInstallBinaries. Those binaries will be automatically downloaded andinstalled to your$GOBIN environment (if not set it will use$GOPATH/bin).It requiresgit and hg for fetching the individual Go packages.


在Vim中使用命令 :GoInstallBinaries 会使用hg下载vim-go使用的二进制工具,具体源码可以查看文件:~/.vim/bundle/vim-go/plugin/go.vim

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. " these packages are used by vim-go and can be automatically installed if  
  2. " needed by the user with GoInstallBinaries  
  3. let s:packages = [  
  4.             \ "github.com/nsf/gocode",   
  5.             \ "code.google.com/p/go.tools/cmd/goimports",   
  6.             \ "code.google.com/p/rog-go/exp/cmd/godef",   
  7.             \ "code.google.com/p/go.tools/cmd/oracle",   
  8.             \ "code.google.com/p/go.tools/cmd/gorename",  
  9.             \ "github.com/golang/lint/golint",   
  10.             \ "github.com/kisielk/errcheck",  
  11.             \ "github.com/jstemmer/gotags",  
  12.             \ ]  

或者使用go get进行下载:

[html]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. gerryyang@mba:~$go get github.com/kisielk/errcheck  
  2. package code.google.com/p/go.tools/go/loader: Get https://code.google.com/p/go/source/checkout?repo=tools: dial tcp 173.194.127.32:443: operation timed out  
  3. package code.google.com/p/go.tools/go/types: Get https://code.google.com/p/go/source/checkout?repo=tools: dial tcp 173.194.127.32:443: operation timed out  


如果下载失败,也可以通过 gopm.io (Download Go packages with version, but no require for version control tools like Git and Hg, etc.) 根据路径单独下载。



参考

[1] Golang开发环境搭建-Vim篇

[2] Go development environment for Vim

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值