Fallback to ag if rg is not present

This commit is contained in:
hophacker 2019-04-11 13:06:33 +08:00
parent 5f84472e2b
commit 156e7fad14
3 changed files with 16 additions and 7 deletions

3
vim/settings/ag.vim Normal file
View File

@ -0,0 +1,3 @@
" Open the Ag command and place the cursor into the quotes
nmap ,ag :Ag ""<Left>
nmap ,af :AgFile ""<Left>

View File

@ -7,6 +7,12 @@ if executable('rg')
" rg is fast enough that CtrlP doesn't need to cache " rg is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0 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 else
" Fall back to using git ls-files if Ag is not available " Fall back to using git ls-files if Ag is not available
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$' let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'

View File

@ -11,20 +11,20 @@ function! GetVisual()
endfunction endfunction
"grep the current word using ,k (mnemonic Kurrent) "grep the current word using ,k (mnemonic Kurrent)
nnoremap <silent> ,k :Rg <cword><CR> nnoremap <silent> ,k :Ag <cword><CR>
"grep visual selection "grep visual selection
vnoremap ,k :<C-U>execute "Rg " . GetVisual()<CR> vnoremap ,k :<C-U>execute "Ag " . GetVisual()<CR>
"grep current word up to the next exclamation point using ,K "grep current word up to the next exclamation point using ,K
nnoremap ,K viwf!:<C-U>execute "Rg " . GetVisual()<CR> nnoremap ,K viwf!:<C-U>execute "Ag " . GetVisual()<CR>
"grep for 'def foo' "grep for 'def foo'
nnoremap <silent> ,gd :Rg 'def <cword>'<CR> nnoremap <silent> ,gd :Ag 'def <cword>'<CR>
",gg = Grep! - using Rg RipGrep" ",gg = Grep! - using Ag the silver searcher
" open up a grep line, with a quote started for the search " open up a grep line, with a quote started for the search
nnoremap ,gg :Rg ""<left> nnoremap ,gg :Ag ""<left>
"Grep for usages of the current file "Grep for usages of the current file
nnoremap ,gcf :exec "Rg " . expand("%:t:r")<CR> nnoremap ,gcf :exec "Ag " . expand("%:t:r")<CR>