转自http://blog.51cto.com/xujpxm/1909043 和 http://dreamlikes.cn/archives/940
所谓打造,其实就是找一些适合自己的插件,先简单总结一些,我亲测过的几个插件。开始之前先说明一点,这里提到的几个插件都是非常强大和有名气的,但所谓适合自己的才是最好的,文中所说的缺点只是相对个人而言的感受,并不适用所有人。分享出来只是为给大家在选择时做个参考。谢谢~
1.vim插件管理器
这两个插件都可谓是vim的神器,用来进行vim的插件管理。pathogen配置好之后使用方便之处在于只需要把你下载的vim插件放到~/.vim/bundle(也可自定义)目录下即可,而vundel每次需要更改vimrc文件,不过vundel的方便之处在于更改完vimrc文件之后,可以直接在vim里使用:PluginInstall来进行插件的一键安装,原理就是自动从GitHub等源上自动下载。
这里我选择的是vundle,因为可以一眼从配置文件看出我安装了哪些插件,不需要的插件直接注释掉即可。如下图Plugin部分就是我安装的插件,一目了然。
2.python支持
既然是写python,那么必然要进行python的扩展,这里我测试了三个比较知名的python插件。
-
Jedi-vim - Vim bindings for the Jedi auto-completion library for Python.
-
Python-mode - An all in one plugin for turning Vim into a Python IDE.
-
YouCompleteMe - Includes Jedi-based completion engine for Python.
对我来说,自动补全,和语法检测是最终选择了使用jedi-vim。
简单说下自己的直观感受:
python-mode:
优点:能够自动补全,自带python语法检测和代码折叠等功能,很强大。
缺点:自动补全时顺带显示函数的帮助信息,页面显示不够简洁、美观;语法检测功能一般。
以下是截图示例:
YouCompleteMe:
优点:自动补全,界面简洁,支持多语言,功能非常强大、完整。三者之中在github上star数量最多。
缺点:可能由于功能过于强大,加语法检测之后加载相对稍慢。配置略繁琐。
jedi-vim:
优点:优点对我来说,就是上面两个的缺点它都弥补了。加载速度挺快,页面也挺简洁。
缺点:没有语法检测;功能没YCM强大,但是够用足矣。
So,最终我选择了jedi-vim。
3.python语法检测
有了自动补全之后就是语法检测,个人倾向pep8标准,而且希望语法错误修正之后能够被编辑器马上识别。
我测过用以下几种做checker:
flake8、pep257、pep8、pycodestyle、syntastic
pydocstyle、pyflakes、pylama、pylint、python
而最终我选择了用插件:"w0rp/ale",它的语法检测最全面,界面简洁,错误修正之后能够被马上识别出,而且是异步的,不必担心加载过慢崩溃等问题。如下图:
4.加强版自动补全
之前提到在vim里面python的自动补全,为了使vim的功能更加强大,介绍一款插件neocomplete.vim,使用它可谓让vim的补全无处不在。如下图它会直接补全shell路径。
需要注意一点:neocomplete requires Vim 7.3.885+ compiled with if_lua。
5.目录树插件
目录树插件自然是NERDTree,外加一个vim-nerdtree-tabs补强功能。效果图如下:
最后还是那句话,适合自己的才是最好的。
===============================================================================================
YouCompleteMe这个Vim插件还真不好安装,挺多坑的,折腾了挺久终于最后用上了。
测试环境:
[broly@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
- 1
- 2
一、更新Vim
我安装这个插件的时候,提示:YouCompleteMe unavailable : YouCompleteMe unavailable: requires Vim 7.4.1578+
所以不得不把系统自带的Vim更新到8.0
# 移除旧版本
sudo yum remove vim -y
# 安装必要组件
sudo yum install ncurses-devel python-devel -y
# 下载源码编译安装
git clone https://github.com/vim/vim.git
cd vim/src
# 根据自己实际情况设置编译参数
./configure --with-features=huge --enable-pythoninterp=yes --enable-cscope --enable-fontset --with-python-config-dir=/usr/lib64/python2.7/config
make
sudo make install
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
编译参数说明:
–with-features=huge:支持最大特性
–enable-rubyinterp:打开对ruby编写的插件的支持
–enable-pythoninterp:打开对python编写的插件的支持
–enable-python3interp:打开对python3编写的插件的支持
–enable-luainterp:打开对lua编写的插件的支持
–enable-perlinterp:打开对perl编写的插件的支持
–enable-multibyte:打开多字节支持,可以在Vim中输入中文
–enable-cscope:打开对cscope的支持
–with-python-config-dir=/usr/lib64/python2.7/config 指定python 路径
–with-python-config-dir=/usr/lib64/python3.5/config 指定python3路径
注意:必须带上Python编写插件支持,最好带上Python路径,否则使用时会报这个错误:YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
编译安装好Vim后,默然是安装在/usr/local/bin目录下,所以把该目录加入到PATH方便terminal全局使用:
sudo nano /etc/profile
- 1
在尾部添加:
export PATH=$PATH:/usr/local/bin/vim
- 1
然后使环境变量生效:
source /etc/profile
- 1
二、安装Vundle和YouCompleteMe
Vundle是Vim的插件管理工具,官方文档:https://github.com/VundleVim/Vundle.vim
安装步骤很简单:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
- 1
编辑配置文件
vim ~/.vimrc
- 1
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/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'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
"Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
" 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/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
Bundle 'altercation/vim-colors-solarized'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'Valloric/YouCompleteMe'
" 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
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
syntax enable
colorscheme monokai
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
- 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
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
这里要注意加上, 在我自己的vimrc上
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
- 1
执行插件安装
vim +PluginInstall +qall
- 1
三、增加配色方案
我这里使用monokai 配色方案 :https://github.com/sickill/vim-monokai
下载对应的monokai.vim 文件 放到 ~/.vim/colors/ 即可
mkdir ~/.vim/colors
wget -O ~/.vim/colors/monokai.vim https://raw.githubusercontent.com/sickill/vim-monokai/master/colors/monokai.vim
- 1
- 2
四、安装Clang
(此步骤可选,因为安装这个是为了C语言家族语法补全功能)
原文说的是这个步骤可选,但是如果不安装Clang,可能会出现 bug:the ycmd server SHUT DOWN (restart with ‘:…low the instructions in the documentation.
sudo yum install cmake -y
cd ~/.vim/plugin/YouCompleteMe
./install.py --clang-completer
- 1
- 2
- 3
五、测试
打开个cpp文件,测试下是否还会报错吧~~
vim demo.cpp