From 6409d7d3f51452b3e599374bb83f0a0e0afae67a Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Wed, 13 Dec 2017 13:13:17 +0100 Subject: Improve grep function --- vim/.vimrc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'vim/.vimrc') diff --git a/vim/.vimrc b/vim/.vimrc index 680acad..00c3816 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -377,7 +377,7 @@ augroup END "" My search if executable("ag") set grepprg=ag\ --vimgrep - set grepformat^=%f:%l:%c:%m + set grepformat=%f:%l:%c:%m endif if executable("rg") @@ -386,13 +386,31 @@ if executable("rg") endif command! -nargs=+ -complete=file_in_path Grep execute 'silent grep!' | cw | redraw! +command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' | cw | redraw! -nmap gs :set opfunc=Searchg@ -xmap gs :call Search(visualmode()) -function! Search(vm) +function! My_search(vm) let is_visual=(a:vm == "v") let l=getline(is_visual ? "'<" : "'[") let [line1,col1] = getpos(is_visual ? "'<" : "'[")[1:2] let [line2,col2] = getpos(is_visual ? "'>" : "']")[1:2] - call feedkeys(':Grep "' . l[col1 - 1: col2 - 1] . '"') + call feedkeys(':' . g:my_searchprg . ' "' . l[col1 - 1: col2 - 1] . '"') +endfunction + +let g:my_searchprg = "Grep" +function! Cycle_searchprg() + if g:my_searchprg == "Grep" + let g:my_searchprg = "GitGrep" + elseif g:my_searchprg == "GitGrep" + let g:my_searchprg = "Grep" + endif + echom g:my_searchprg endfunction + +nmap cog :call Cycle_searchprg() +nmap gs :set opfunc=My_searchg@ +xmap gs :call Search(visualmode()) + +" nmap gs :let g:my_searchprg="Grep":set opfunc=My_searchg@ +" nmap g/ :let g:my_searchprg="GitGrep":set opfunc=My_searchg@ +" xmap gs :let g:my_searchprg="Grep":call Search(visualmode()) +" xmap g/ :let g:my_searchprg="GitGrep":call Search(visualmode()) -- cgit v1.2.3