From 156e7fad14b3f17a8f32385d024c031170f2669f Mon Sep 17 00:00:00 2001 From: hophacker Date: Thu, 11 Apr 2019 13:06:33 +0800 Subject: [PATCH] Fallback to ag if rg is not present --- vim/settings/ag.vim | 3 +++ vim/settings/ctrlp.vim | 6 ++++++ vim/settings/search.vim | 14 +++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 vim/settings/ag.vim diff --git a/vim/settings/ag.vim b/vim/settings/ag.vim new file mode 100644 index 0000000..a6dcd27 --- /dev/null +++ b/vim/settings/ag.vim @@ -0,0 +1,3 @@ +" Open the Ag command and place the cursor into the quotes +nmap ,ag :Ag "" +nmap ,af :AgFile "" diff --git a/vim/settings/ctrlp.vim b/vim/settings/ctrlp.vim index 0f81282..9eefcf8 100644 --- a/vim/settings/ctrlp.vim +++ b/vim/settings/ctrlp.vim @@ -7,6 +7,12 @@ if executable('rg') " rg is fast enough that CtrlP doesn't need to cache let g:ctrlp_use_caching = 0 +elseif executable('ag') + " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore + let g:ctrlp_user_command = 'ag %s --files-with-matches -g "" --ignore "\.git$\|\.hg$\|\.svn$"' + + " ag is fast enough that CtrlP doesn't need to cache + let g:ctrlp_use_caching = 0 else " Fall back to using git ls-files if Ag is not available let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$' diff --git a/vim/settings/search.vim b/vim/settings/search.vim index 49c4612..82cf075 100644 --- a/vim/settings/search.vim +++ b/vim/settings/search.vim @@ -11,20 +11,20 @@ function! GetVisual() endfunction "grep the current word using ,k (mnemonic Kurrent) -nnoremap ,k :Rg +nnoremap ,k :Ag "grep visual selection -vnoremap ,k :execute "Rg " . GetVisual() +vnoremap ,k :execute "Ag " . GetVisual() "grep current word up to the next exclamation point using ,K -nnoremap ,K viwf!:execute "Rg " . GetVisual() +nnoremap ,K viwf!:execute "Ag " . GetVisual() "grep for 'def foo' -nnoremap ,gd :Rg 'def ' +nnoremap ,gd :Ag 'def ' -",gg = Grep! - using Rg RipGrep" +",gg = Grep! - using Ag the silver searcher " open up a grep line, with a quote started for the search -nnoremap ,gg :Rg "" +nnoremap ,gg :Ag "" "Grep for usages of the current file -nnoremap ,gcf :exec "Rg " . expand("%:t:r") +nnoremap ,gcf :exec "Ag " . expand("%:t:r")