1. 我平时喜欢IDE与Vim混用,IDE可以配一键开VIM。

2. 由于开发以IDE为主Vim为辅助,基本上不装太酷炫的插件。常用的插件是:

Plugin 'https://github.com/easymotion/vim-easymotion.git'
Plugin 'git://github.com/tpope/vim-surround.git'
Plugin 'kshenoy/vim-signature'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'junegunn/vim-easy-align'
Plugin 'https://github.com/gcmt/taboo.vim.git'
Plugin 'https://github.com/mhinz/vim-grepper.git'
Plugin 'https://github.com/Chun-Yang/vim-action-ag.git'
Plugin 'https://github.com/Valloric/YouCompleteMe.git'
Plugin 'https://github.com/kien/rainbow_parentheses.vim'
Plugin 'https://github.com/tpope/vim-fugitive.git'
Plugin 'junegunn/fzf.vim'

重点推荐 vim-multiple-cursors和vim-easy-align,在IDE中开VIM往往是为了用这两个功能。

3. 一些常用配置项目

  • 交换区域内容 (先删除区域A,然后选中区域B,按快捷键交换A,B内容)
"Swap
vnoremap <C-S-X> <ESC>`.``gvp``P
  • 当前光标所在词转大写并保持原来的光标位置和插入状态 (避免用CapsLock后忘了切回来光标乱飞,直接小写输入然后按键转大写)
nmap <C-S-U> gUiwe
imap <C-S-U> <ESC>gUiwgi
  • 提示输入正则表达式,把匹配行抽取到buffer末尾
function! CopyToBottom()
    let l:a = input("Copy to bottom with Regex: ")
    execute "g/".l:a."/t$"
endfunction

noremap <Leader>zg :call CopyToBottom()<CR>
  • 选中刚刚粘贴的内容
" select the pasted block
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
  • 折叠其他内容只留下匹配之前一次search的行
nnoremap zpr :setlocal foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum-1)=~@/)\\|\\|(getline(v:lnum+1)=~@/)?1:2 foldmethod=expr foldlevel=0 foldcolumn=2<CR>:set foldmethod=manual<CR><CR>

4. 擅用!命令

比如说,在shell里安装

npm install -g js-beautifier
npm install -g esprima
在vim中选中文本后可以用 !html-beautify 或 !js-beautify 格式化html或js代码,可以用!esvalidate查找大段js代码中的语法错误。