各个平台下Gvim的安装所踩到的坑

这篇随笔主要是对Linux和Windows下gvim8.0(python支持)的安装笔记,并且安装YCM插件.

Linux

1.scientific_linux 下安装Vim8并支持Python3

(1)安装依赖项

1
2
3
4
5
6
7
8
sudo yum install ncurses-devel
sudo yum install libXt-devel
sudo yum install gnome-software-devel.x86_64 
sudo yum install gnome-desktop3-devel.x86_64 
sudo yum install libgnomeui-devel.x86_64 
sudo yum install libgnome-devel.i686
sudo yum install ruby-devel.x86_64 
sudo yum install lua-devel.x86_64

(2)从github下载vim

新建一个文件夹存放clone下来的vim,然后在该文件夹下打开终端执行命令:

1
git clone https://github.com/vim/vim.git

(3)删除系统中vim

1
sudo yum remove vim-* -y

删除原有的vim同时, 会删除sudo命令, 所以必须重新安装sudo, 此时会安装一个最小版本的vim即vi

1
sudo yum install sudo

(4)./configure 配置 vim

进入下载的VIM目录,执行下面的操作: 注意,有的文章中这里同时配置了python2和python3,此时只有python2生效,如果想让vim8支持python3,则只需要配置python3即可,不要配置python2: 支持python3:

1
2
3
4
5
6
7
8
sudo ./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp=yes \
            --enable-python3interp=yes \
            --with-python3-config-dir=/usr/local/python3/lib/python3.6/config-3.6m-x86_64-linux-gnu \
            --enable-perlinterp=yes \
            --enable-luainterp=yes \
            --enable-gui=gtk3 --enable-cscope --prefix=/usr/local/vim

如果想让vim8支持python2,执行下面的操作:

1
2
3
4
5
6
7
8
sudo ./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp=yes \
            --enable-pythoninterp=yes \
            --with-python-config-dir=/usr/lib/python2.7/config \ 
            --enable-perlinterp=yes \
            --enable-luainterp=yes \
            --enable-gui=gtk3 --enable-cscope --prefix=/usr

注意: --with-python-config-dir= 后面必须是python2.7的config

(5)执行make安装

1
2
sudo make
sudo make install

(6)查看结果

vim –version

2.使用bundle管理插件

安装见网址: https://github.com/gmarik/vundle.git

在vimrc文件中添加如下内容来启用vundle管理vim插件的功能:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
set nocompatible              " be iMproved, required
filetype off                  " required
" set the runtime path to include Vundle and initialize
"set rtp+=.vim
set rtp+=/usr/local/vim/share/vim/vim81/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on

3.scientific_linux 下安装 YouCompleteMe

1.需要提前安装的软件.

git

1
sudo yum install build-essential git

也可以自己下在源文件编译安装.

cmake:

1
sudo yum install build-essential cmake

2.安装YouCompleteMe

为了方便维护,统一使用指定路径的方式安装: 在vimrc第一行添加:

1
set runtimepath+=~/.vim/bundle/YouCompleteMe

(1)下载YouCompleteMe安装包

使用git:

1
git clone --recursive https://github.com/Valloric/YouCompleteMe.git

确认仓库的完整性:

1
git submodule update --init --recursive

将YouCompleteMe放到 ~/.vim/bundle/ 下.

(2)编译安装YouCompleteMe

64位系统: (YouCompleteMe 自带64位的clang库)

1
2
cd ~/.vim/bundle/YouCompleteMe
sudo ./install.sh --clang-completer

注意: 必须要联网, 会自动下载clang的lib

(3)编译错误的解决办法

1.可以先查看一下含python-devel的包

1
yum search python | grep python-devel

2.64位安装python-devel.x86_64,32位安装python-devel.i686,我这里安装:

1
sudo yum install python-devel.x86_64

3后续配置

C/c++ 1.在vimrc中添加:

1
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

2.修改.ycm_extra_conf.py文件, 添加自己系统的头文件路径. 3.完善YouCompleteMe 配置: 在vimrc中添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"禁止YCM 自动弹出函数原型预览窗口
set completeopt=menu,menuone
let g:ycm_add_preview_to_completeopt = 0
" 补全功能在注释中同样有效  
let g:ycm_complete_in_comments=1 
" 语法关键字补全              
let g:ycm_seed_identifiers_with_syntax=1  
"输入1个字符-->自动弹出补全.
let g:ycm_semantic_triggers =  {
            \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
            \ 'cs,lua,javascript': ['re!\w{2}'],
            \ }
"set YouCompleteMe白名单, please delete "(),keep \ ,when you use it
let g:ycm_filetype_whitelist = { 
            \ 'cpp' : 1,
            \ 'python' : 1,
            \ 'css' : 1,
            \ 'c' : 1,
            \ 'h' : 1,
            \ 'hpp' :1,
            \ 'objc' :1,
            \}
"let g:ycm_key_list_select_completion = ['<c-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
"屏蔽 YCM 的诊断信息
"let g:ycm_show_diagnostics_ui = 0

注: 其他细节可以参考博文: http://www.cnblogs.com/yongjiuzhizhen/p/4793498.html

Windows

1.Windows 添加vim至右键菜单(windows)

(1)添加edit with vim选项,每个文件打开一个新窗口。 新建reg文件:

1
2
3
4
5
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\edit with vim]
@="edit with vim"
[HKEY_CLASSES_ROOT\*\Shell\edit with vim\command]
@="\"D:\Program Files\Vim\vim80\gvim.exe\" -p --remote-tab-silent \"%1\""

(2)为vim选项加入图标。 新建reg文件:

1
2
3
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\edit with vim]
"Icon"="D:\Program Files\Vim\vim80\gvim.exe"

注意:要将上面的reg代码做相应的修改(将键值的目录改成你自己的VIM安装目录)

2.用vundle管理vim插件

安装vundle (保证git.exe在你的环境变量中.)

1
git clone https://github.com/gmarik/vundle "D:\Program Files (x86)\vim\vimfiles\bundle\vundle"

在_vimrc文件中添加如下内容来启用vundle管理vim插件的功能:

1
2
3
4
5
6
"vundle配置
set rtp+=$VIM/vimfiles/bundle/vundle/
call vundle#rc('$VIM/vimfiles/bundle/')
Bundle 'gmarik/vundle'
" automatically detect file types.
filetype plugin indent on     

通过vundle安装vim 插件, 在gvim内执行: BundleInstall

3.Windows下安装YCM插件

我用的是知乎大神编译的现成文件,贴地址: https://www.zhihu.com/question/25437050

以及YCM中的相关配置: https://zhuanlan.zhihu.com/p/33046090