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聽cmake sudo聽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聽YCM Plugin'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聽smarttab setshiftwidth=4 set聽tabstop=4 setsofttabstop=4 set聽expandtab autocmdFileType聽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
本文出自 “说话的白菜” 博客,谢绝转载!
有疑问加站长微信联系(非本文作者)