Golang vim開發環境設置

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章