Move this Ag stuff into a function, remove flickers

Fri, 18 Oct 2019 14:05:27 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 18 Oct 2019 14:05:27 -0400
changeset 803
ffc6f9c140cd
parent 802
8e0452d9316c
child 804
17b16f2ff839

Move this Ag stuff into a function, remove flickers

.vim/autoload/vimrc.vim file | annotate | diff | comparison | revisions
.vimrc file | annotate | diff | comparison | revisions
--- a/.vim/autoload/vimrc.vim
+++ b/.vim/autoload/vimrc.vim
@@ -31,6 +31,27 @@ func! vimrc#AutoSessionConfig() abort
   endif
 endfunc
 
+func! vimrc#Ag(args) abort
+  let orig_t_ti = &t_ti
+  let orig_t_te = &t_te
+  let orig_shellpipe = &shellpipe
+
+  set t_ti= t_te=
+  let &shellpipe = substitute(&shellpipe, '| tee', ' >', '')
+
+  try
+    silent! execute "grep " . escape(a:args, '|')
+    copen
+
+    let @/ = matchstr(a:args, "\\v(-)\@<!(\<)\@<=\\w+|['\"]\\zs.{-}\\ze['\"]")
+    call feedkeys(":let &hlsearch=1 \| echo \<CR>", 'n')
+  finally
+    let &t_ti = orig_t_ti
+    let &t_te = orig_t_te
+    let &shellpipe = orig_shellpipe
+  endtry
+endfunc
+
 func! vimrc#Gcd() abort
   let root = system('git rev-parse --show-toplevel 2>/dev/null')[:-2]
   if ! v:shell_error
--- a/.vimrc
+++ b/.vimrc
@@ -126,7 +126,7 @@ command! Gcd call vimrc#Gcd()
 command! Hgcd call vimrc#Hgcd()
 command! SyntaxCompleteOn setl omnifunc=syntaxcomplete#Complete
 
-command! -nargs=+ -complete=file -bar Ag  sil! gr <args>|cope|redr!|let @/="<args>"|set hls
+command! -nargs=+ -complete=file -bar Ag call vimrc#Ag(<q-args>)
 CAlias Rg Ag
 
 CAlias Q q
@@ -232,10 +232,10 @@ if has('persistent_undo')
 endif
 
 if executable('rg')
-  set grepprg=rg\ --vimgrep\ --no-heading
+  set grepprg=rg\ --vimgrep
   set grepformat=%f:%l:%c:%m,%f:%l%m,%f\ \ %l%m
 elseif executable('ag')
-  set grepprg=ag\ --nogroup\ --nocolor\ --vimgrep
+  set grepprg=ag\ --vimgrep
   set grepformat^=%f:%l:%c:%m
 endif
 

mercurial