在這篇部落格中,介紹了把vim打造成C++IDE的方法。Golang有更好的vim-go插件,是以重新把vim配置為Golang的IDE。
安裝Vundle插件管理工具:
在
~
目錄下,執行:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
指令。
在
~
目錄下建立或者重寫
.vimrc
檔案,輸入:
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
call vundle#end()
之後打開vim,輸入
:PluginInstall
即可,即可完成
Vundle
的安裝。
安裝必要的插件:
直接在vimrc中進行如下的替換,注意leader鍵設定為了
;
set nocompatible
filetype off
set tabstop=4
set shiftwidth=4
set expandtab
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'scrooloose/nerdtree'
Plugin 'Valloric/YouCompleteMe'
call vundle#end()
filetype plugin indent on
let mapleader=";"
map <leader>n :NERDTreeToggle<CR>
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:ycm_add_preview_to_completeopt = 0
let g:ycm_min_num_of_chars_for_completion = 1
let g:ycm_auto_trigger = 1
set completeopt-=preview
打開vim輸入:
:PluginInstall
。進行插件安裝。注意YoucompleteMe安裝時間比較長。
所有插件安裝完畢後,需要單獨編譯YouCompleteMe,需要提前安裝必要元件:
sudo apt-get install vim
sudo apt-get install g++
sudo apt-get install python
sudo apt-get install build-essential cmake python3-dev
之後,執行:
cd ~/.vim/bundle/YouCompleteMe/
./install.py --go-completer
需要臨時定義GOPATH,代碼:
export GOPATH=~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/
然後跳轉到
YouCompleteMe/third_party/ycmd/third_party/go
目錄下,該目錄有兩個子目錄,分别是:
src/github.com/mdempsky/gocode
和
src/github.com/rogpeppe/godef
。分别轉到這兩個目錄下,都執行
go build
指令即可。
之後在自己工程的目錄下,建立
.ycm_extra_conf.py
檔案,裡面添加上自己所在的路徑和golang語言的路徑即可