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

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

2014-11-09 wcdj


摘要:之前總結過在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的相關配置:

" -------------" Vundle" https://github.com/gmarik/Vundle.vim" -------------set nocompatible              " be iMproved, requiredfiletype off                  " required" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, requiredPlugin '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'}" Install Vim-goPlugin 'fatih/vim-go'" All of your Plugins must be added before the following linecall vundle#end()            " requiredfiletype plugin indent on    " required" To ignore plugin indent changes, instead use:"filetype plugin on"" Brief help" :PluginList       - lists configured plugins" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate" :PluginSearch foo - searches for foo; append `!` to refresh local cache" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal"" see :h vundle for more details or wiki for FAQ" 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

" these packages are used by vim-go and can be automatically installed if" needed by the user with GoInstallBinarieslet s:packages = [            \ "github.com/nsf/gocode",             \ "code.google.com/p/go.tools/cmd/goimports",             \ "code.google.com/p/rog-go/exp/cmd/godef",             \ "code.google.com/p/go.tools/cmd/oracle",             \ "code.google.com/p/go.tools/cmd/gorename",            \ "github.com/golang/lint/golint",             \ "github.com/kisielk/errcheck",            \ "github.com/jstemmer/gotags",            \ ]

或者使用go get進行下載:

gerryyang@mba:~$go get github.com/kisielk/errcheckpackage 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 outpackage 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



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.