工欲善其事,必先利其器。熟练使用这些插件,开发起来会事半功倍
Vundle
官方推荐使用vim插件管理工具
安装1
$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置.vimrc1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21$ touch ~/.vimrc
set nocompatible " 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 'gmarik/Vundle.vim'
" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
安装1
2$ vim
$ :PluginInstall
Powerline
该工具可以很优雅的显示vim下方的工具栏1
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
修改.vimrc1
2$ vim ~/.vimrc
set laststatus=2
Solarized
1 | Plugin 'altercation/vim-colors-solarized' |
YouCompleteMe
代码补全神器,但是安装也非常复杂,并不想其他插件那样一行命令就可以搞定
首先还是配置来源1
Plugin 'Valloric/YouCompleteMe'
保存退出后打开vim,在正常模式下输入1
:PluginInstall
等待Vundle将YouCompleteMe安装完成,这个过程会很漫长,除非你的网络环境很好,最好翻墙
最后进行编译1
2$ cd ~/.vim/bundle/YouCompleteMe
$ ./install.sh --clang-completer
如果不需要c-family的补全,可以去掉–clang-completer。如果需要c#的补全,请加上–omnisharp-completer。
默认使用本地py2的环境进行安装,但是执行install.sh,提示过期,如果使用install.py安装还是修改~/.bash_profile1
export PYTHON_CONFIGURE_OPTS="--enable-framework"
执行1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16重新使用pyenv下载一个虚拟环境,在install即可
## tarbar
github:https://github.com/majutsushi/tagbar
### 安装
依赖 vim>7.0 和 [Exuberant ctags](http://ctags.sourceforge.net/)
```bash
# ubuntu
sudo apt-get install ctags
# centos
sudo yum install ctags
# mac
brew install ctags
在vim中安装1
Plugin 'majutsushi/tagbar'
使用
配置快捷键t,编辑文件时按t,自动进入,jk上下移动,回车选中跳转
最终配置1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16Plugin 'majutsushi/tagbar'
nmap t :TagbarToggle<CR>
" 启动时自动focus
let g:tagbar_autofocus = 1
" for ruby, delete if you do not need
let g:tagbar_type_ruby = {
\ 'kinds' : [
\ 'm:modules',
\ 'c:classes',
\ 'd:describes',
\ 'C:contexts',
\ 'f:methods',
\ 'F:singleton methods'
\ ]
\ }
配置markdown
vim ~/.ctags1
2
3
4
5--langdef=markdown
--langmap=markdown:.mkd
--regex-markdown=/^#[ \t]+(.*)/\1/h,Heading_L1/
--regex-markdown=/^##[ \t]+(.*)/\1/i,Heading_L2/
--regex-markdown=/^###[ \t]+(.*)/\1/k,Heading_L3/
vim ~/.vimc1
2
3
4
5
6
7
8let g:tagbar_type_markdown = {
\ 'ctagstype' : 'markdown',
\ 'kinds' : [
\ 'h:Heading_L1',
\ 'i:Heading_L2',
\ 'k:Heading_L3'
\ ]
\ }
命令
1 | 跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样 |
更多
文档:https://github.com/majutsushi/tagbar/wiki
quickrun
快速执行
github:https://github.com/thinca/vim-quickrun
安装
1 | Plugin 'thinca/vim-quickrun' " 快速执行 |
配置
1 | let g:quickrun_config = { |
airline
增强状态栏
安装
1 | Plugin 'bling/vim-airline' " 状态栏 |
配置
1 | if !exists('g:airline_symbols') |
nerdcommenter
快速注释/放开注释
github:https://github.com/scrooloose/nerdcommentera
安装
1 | Plugin 'scrooloose/nerdcommenter' |
使用
官方快键键,更多用法见快捷键1
2<header>c<space> # 自动判断注释还是放开注释
<header>cy # 添加注释后自动
配置
常用配置,更多见文档1
let g:NERDSpaceDelims = 1 # 注释后添加空格,推荐
gundo.
查看/跳转历史记录
github:https://github.com/sjl/gundo.vim
安装
1 | Plugin 'sjl/gundo.vim' " 查看文件编辑历史记录 |
配置
1 | nnoremap <leader>h :GundoToggle<CR> |
使用
1 | 使用;h打开历史记录,使用<ctrl>w+hl左右移动窗口,在历史记录窗口使用jk上下移动, |
vim-expand-region
区域选择
安装
1 | Plugin 'terryma/vim-expand-region' |
配置
自定义快捷键 v 区域选择、V 取消选择 这样比较符合vim本身习惯1
2vmap v <Plug>(expand_region_expand)
vmap V <Plug>(expand_region_shrink)
更多
见 文档
vim-easy-align 快速对齐
安装
1 | Plugin 'junegunn/vim-easy-align' |
配置
1 | vmap <Leader>a <Plug>(EasyAlign) |
使用
绑定快捷键1
2
3
4
5
6
7
8
9
10
11
12<Leader>a= 对齐等号表达
<Leader>a: 对齐冒号表达式(json/map等)
# 默认左对齐
<Leader>a<space> 首个空格对齐
<Leader>a2<space> 第二个空格对齐
<Leader>a-<space> 倒数第一个空格对齐
<Leader>a-2<space> 倒数第二个空格对齐
<Leader>a*<space> 所有空格依次对齐
# 右对齐
<Leader>a<Enter>*<space>
更多
见 文档
