Golang vim开发环境设置

1 简介
html

    上一篇博客咱们介绍了Golang的安装、编译、运行,本篇博客咱们介绍如何设置面向Golang的vim开发环境。原生的vim没法自行识别golang关键字,开发环境如同编辑普通文本文件,没法高亮显示,更不要说自动补全等功能。为此,咱们须要在vim中加入面向golang的插件vim-go。同时,根据vim-go的安装引导,咱们还须要安装YouCompleteMe(YCM)。python


2 安装Vundlegit

Vundle的git页面 https://github.com/VundleVim/Vundle.vimgithub

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

3 安装vim-go
golang

vim-go的git页面 https://github.com/fatih/vim-go vim

git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go

4 安装YCMbash

YCM的git页面 https://github.com/Valloric/YouCompleteMeapp

4.1 前提条件
ide

vim版本7.3.584以上ui

安装依赖

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