這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
1 簡介
聽 聽 上一篇部落格我們介紹了Golang的安裝、編譯、運行,本篇部落格我們介紹如何設定面向Golang的vim開發環境。原生的vim無法自行識別golang關鍵字,開發環境如同編輯普通文字檔,無法高亮顯示,更不要說自動補全等功能。為此,我們需要在vim中加入面向golang的外掛程式vim-go。同時,根據vim-go的安裝引導,我們還需要安裝YouCompleteMe(YCM)。
2 安裝Vundle
Vundle的git頁面聽https://github.com/VundleVim/Vundle.vim
git聽clone聽https://github.com/gmarik/Vundle.vim.git聽~/.vim/bundle/Vundle.vim
3 安裝vim-go
vim-go的git頁面 https://github.com/fatih/vim-go
git聽clone聽https://github.com/fatih/vim-go.git聽~/.vim/bundle/vim-go
4 安裝YCM
YCM的git頁面 https://github.com/Valloric/YouCompleteMe
4.1 前提條件
vim版本7.3.584以上
安裝依賴
sudo聽apt-get聽install聽build-essential聽cmakesudo聽apt-get聽install聽python-dev
4.2 git clone
git聽clone聽https://github.com/Valloric/YouCompleteMe.git聽~/.vim/bundle/YouCompleteMe
4.3 編譯安裝
進入~/.vim/bundle/YouCompleteMe目錄,執行
git聽submoduleupdate聽--init聽--recursive./install.py聽–clang-completer聽–gocode-completer
這兩條命令執行時間較長,尤其第一條,可以並行做點別的。
5 配置
編輯~/.vimrc
"-------------聽聽"Vundle聽聽"https://github.com/gmarik/Vundle.vim聽聽"-------------聽聽聽聽setnocompatible聽聽聽聽聽聽聽聽聽聽聽聽聽聽"聽beiMproved,聽required聽聽filetypeoff聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"聽required聽聽聽聽"聽set聽theruntime聽path聽to聽include聽Vundle聽and聽initialize聽setrtp+=~/.vim/bundle/Vundle.vim聽聽callvundle#begin()聽聽"alternatively,聽pass聽a聽path聽where聽Vundle聽should聽install聽plugins聽聽"callvundle#begin('~/some/path/here')聽聽聽聽"聽letVundle聽manage聽Vundle,聽required聽聽Plugin'gmarik/Vundle.vim'聽聽聽聽"聽Thefollowing聽are聽examples聽of聽different聽formats聽supported.聽聽"聽KeepPlugin聽commands聽between聽vundle#begin/end.聽"聽pluginon聽GitHub聽repo聽聽""Plugin'tpope/vim-fugitive'聽聽"聽pluginfrom聽http://vim-scripts.org/vim/scripts.html聽""Plugin'L9'聽聽"聽Gitplugin聽not聽hosted聽on聽GitHub聽聽""Plugin'git://git.wincent.com/command-t.git'聽聽"聽gitrepos聽on聽your聽local聽machine聽(i.e.聽when聽working聽on聽your聽own聽plugin)聽聽""Plugin'file:///home/gmarik/path/to/plugin'聽聽"聽Thesparkup聽vim聽script聽is聽in聽a聽subdirectory聽of聽this聽repo聽called聽vim.聽聽"聽Passthe聽path聽to聽set聽the聽runtimepath聽properly.聽""Plugin'rstacruz/sparkup',聽{'rtp':聽'vim/'}聽聽"聽Avoid聽aname聽conflict聽with聽L9聽聽""Plugin'user/L9',聽{'name':聽'newL9'}聽聽聽聽"聽InstallVim-go聽聽Plugin'fatih/vim-go'聽聽"聽Install聽YCMPlugin'Valloric/YouCompleteMe'聽聽"聽All聽ofyour聽Plugins聽must聽be聽added聽before聽the聽following聽line聽聽callvundle#end()聽聽聽聽聽聽聽聽聽聽聽聽"required聽聽filetypeplugin聽indent聽on聽聽聽聽"聽required聽聽"聽Toignore聽plugin聽indent聽changes,聽instead聽use:聽"filetypeplugin聽on聽聽"聽聽"聽Briefhelp聽聽":PluginList聽聽聽聽聽聽聽-聽lists聽configuredplugins聽聽":PluginInstall聽聽聽聽-聽installs聽plugins;append聽`!`聽to聽update聽or聽just聽:PluginUpdate聽":PluginSearch聽foo聽-聽searches聽for聽foo;聽append聽`!`聽to聽refresh聽local聽cache聽聽":PluginClean聽聽聽聽聽聽-聽confirms聽removal聽ofunused聽plugins;聽append聽`!`聽to聽auto-approve聽removal聽聽"聽聽"聽see聽:hvundle聽for聽more聽details聽or聽wiki聽for聽FAQ聽聽"聽Putyour聽non-Plugin聽stuff聽after聽this聽line聽聽set聽smarttabsetshiftwidth=4set聽tabstop=4setsofttabstop=4set聽expandtabautocmdFileType聽go聽set聽expandtab
6 參考
https://github.com/gmarik/Vundle.vim
http://studygolang.com/articles/2927
https://github.com/fatih/vim-go
http://howiefh.github.io/2015/05/22/vim-install-youcompleteme-plugin/
https://github.com/Valloric/YouCompleteMe
本文出自 “說話的白菜” 部落格,謝絕轉載!