重玩 vim 之琐碎记录——安装 ag.vim

浏览: 21 发布日期: 2016-11-12 分类: vim

Ag(The Silver Searcher)和 Ack 都是 CLI 的全局搜索工具,其中 Ag 更快一些,而 Ack 也比 Vim 自带的 grep 快很多。

安装Ag

# Ubuntu

sudo apt-get install silversearcher-ag

# .vimrc 添加以下代码,并执行 vundleInstall

" vundle plugins
Plugin 'rking/ag.vim'

# .vimrc ag.vim 配置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Ag searching and cope displaying
"    requires ag.vim - it's much better than vimgrep/grep
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" When you press gv you Ag after the selected text
vnoremap <silent> gv :call VisualSelection('gv', '')<CR>

" Open Ag and put the cursor in the right position
map <leader>g :Ag 

" When you press <leader>r you can search and replace the selected text
vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>

" Do :help cope if you are unsure what cope is. It's super useful!
"
" When you search with Ag, display your results in cope by doing:
"   <leader>cc
"
" To go to the next search result do:
"   <leader>n
"
" To go to the previous search results do:
"   <leader>p
"
map <leader>cc :botright cope<cr>
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
map <leader>n :cn<cr>
map <leader>p :cp<cr>
返回顶部