用vim打造理想的IDE
简介
前言
对于一个开发者而言,使用vim可以说是又爱又恨,一个追求高效的开发者决不能容忍一个开发工具不能自动补全,没有目录导航和函数导航,参考 vim实用技巧实用技巧后,我将常用的插件集成到vim,并做好配置,vimplus就运运而生了,如果喜欢的朋友请不要吝啬,给个star,废话不多说,直接上安装步骤:
下面是我配置的vim.
安装
Ubuntu x64 Installation(Supported Ubuntu 16.04 LTS)
git clone https://git.oschina.net/phper95/vimplus.git
cd ./vimplus
sudo ./install.sh
现在vimplus支持ubuntu14.04之后的所有ubuntu 64位系列以及centos7 64位,运行install.sh脚本,你就可以一边喝咖啡,一遍看着屏幕刷刷刷的打印就安装部署好了开发环境了,整个过程大约持续40分钟,其中下载编译ycm耗费了大半时间,我有下载好了的YouCompleteMe.tar.gz,省得在github上去下载,很慢的,你懂的,若想要手动安装ycm,需要修改vimplus目录下的.vimrc文件。
Plugin ‘Valloric/MatchTagAlways’
Plugin ‘Valloric/YouCompleteMe’
Plugin ‘docunext/closetag.vim’
将ycm插件那行注释掉,不然还会再去下载ycm,ycm可以最后等vimplus执行完成后再安装~~,接下来需要手动编译ycm。
cd ~
mv ~/vimplus/YouCompleteMe ~/.vim/bundle/
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
编译安装完成之后取消~/.vimrc中的#Plugin ‘Valloric/YouCompleteMe’行的注释
vimplus将自动安装一些软件,比如说
- vim
- g++
- ctags
- cmake
- python2
- python3
and some plugins below:
- Vundle
- YouCompleteMe
- NerdTree
- nerdcommenter
- Airline
- auto-pairs
- DoxygenToolkit
- ctrlp
- tagbar
- vim-devicons
- vim-surround
- vim-commentary
- vim-repeat
- vim-endwise
- tabular
- vim-dirdiff
- vim-coloresque
- incsearch.vim
- vim-startify
- change-colorscheme(I am the author)
- etc…
Centos x64 的安装
git clone https://git.oschina.net/phper95/vimplus.git
cd ./vimplus
sudo ./install.sh
运行 install.sh
脚本后会自动安装和配置 vim, 安装号是大约 40 minutes, 主要是由于下载和便宜 Valloric/YouCompleteMe 需要很长时间, 请耐心等待,安装完成之后将会安装如下软件:
- vim
- g++
- ctags
- cmake
- python2
- python3
和一些插件:
- Vundle
- YouCompleteMe
- NerdTree
- nerdcommenter
- Airline
- auto-pairs
- DoxygenToolkit
- ctrlp
- tagbar
- vim-devicons
- vim-surround
- vim-commentary
- vim-repeat
- vim-endwise
- tabular
- vim-dirdiff
- vim-coloresque
- incsearch.vim
- vim-startify
- change-colorscheme(I am the author)
- etc…
配置 YouCompleteMe
到这一步,安装已经完成,你会发现~目录有两个文件,一个是vim的配置文件.vimrc,一个是YouCompleteMe的配置文件.ycm_extra_conf.py,一般来说建立一个main.cpp来写C、C++程序来说是没有问题的,都会有语法补全,当你需要写一些项目并涉及到第三方库时,就需要更改.ycm_extra_conf.py了,具体步骤如下。
将.ycm_extra_conf.py拷贝的项目的根目录。
更改.ycm_extra_conf.py里面的flags变量,添加三方库路径和工程子目录路径。
桌面版linux使用vim-devicons插件会出现乱码,需要设置终端字体为Droid Sans Mono for Powerline Nerd Font Complete,使用xshell等工具连接服务器linux的用户就没有必要使用vim-devicons了,可以在插件目录将vim-devicons目录删除,不然会导致NerdTree的缩进有问题。
快捷键
- Directory tree
<F3>
- Display functions, global variables, macro definitions
<F4>
- Display static code analysis
<F5>
- .h .cpp file quickly switch
<F2>
- Go to declaration
<, + u>
- Go to definition
<, + i>
- Open the include file
<, + o>
- Buffer switch
<Ctrl + P/Ctrl + N>
- Cursor position switch
<Ctrl + O/Ctrl + I>
- Fuzzy Find File
<Ctrl + f>
- Surround
<ys{motion or text-object}{char}/cs{orig_char}{dest_char}/ds{char}>
- Comment code
<gcc/gcap/gc/,ca/,cA>
- DirDiff
:DirDiff <dir1> <dir2>
- Repeat
.
- Change the colorscheme
<F10/F9>
特性展示
语法补全
YouCompleteMe传说中最全最好用的补全插件
Full path fuzzy file, buffer, mru, tag
ctrlp ctrlp提供文件搜索,支持模糊查询。
vim-airline
提供漂亮的状态栏支持
vim-surround
Surround a vim text object with a pair of symmetrical chars. We can also remove or change the ones already there.
vim-commentary
An extremely easy tool to toggle commentary in lines and visual selections. We only need to enter a mapping and a movement to do the action, as simple as that.
auto-pairs
auto-pairs provides smart auto-completion for delimiters like (), {}, [], “”, ”, “.
incsearch.vim
vim-devicons
vim-coloresque
vim-dirdiff
vim-startify
Change the colorscheme
兴趣是最好的老师,我的github地址:https://git.oschina.net/phper95/
Warning
- If poor network conditions may fail to install, basically Valloric/YouCompleteMe installation fails, after a failed installation will need to
rm -rf ~/.vim/bundle/YouCompleteMe
, and then re-execute theinstall.sh
can be re-installed, the program will automatically install the plug-in installation fails,or I have YouCompleteMe.tar.gz,download it and thentar -xvf YouCompleteMe.tar.gz -C ~/.vim/bundle/
,thencd ~/.vim/bundle/YouCompleteMe
and runpython ./install.py --clang-completer
.
1.如果网络条件不好可能安装失败,基本上是Valloric/YouCompleteMe安装失败,安装失败后需要将~/.vim/bundle文件夹下的YouCompleteMe目录删除,然后重新执行setup.sh即可,重新安装时,程序将自动安装安装失败的插件。
2.在ubuntu16.04LTS下安装可能会失败(Valloric/YouCompleteMe安装失败),因为vim默认支持python3进行插件编译,安装失败后,手动进入~/.vim/bundle/YouCompleteMe,然后运行python3 ./install.py –clang-completer即可。