在这篇博客中,介绍了把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语言的路径即可