summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2017-12-13 13:13:17 +0100
committerUrbain Vaes <urbain@vaes.uk>2017-12-13 13:57:47 +0100
commit6409d7d3f51452b3e599374bb83f0a0e0afae67a (patch)
tree70765a7f807eff4108d9d2b61d692a7d92a2ee11
parent7bcbd631e3973f86905fbc5769850dc795bfdc38 (diff)
Improve grep function
-rw-r--r--vim/.vimrc28
1 files changed, 23 insertions, 5 deletions
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!' <q-args> | cw | redraw!
+command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' <q-args> | cw | redraw!
-nmap gs :set opfunc=Search<cr>g@
-xmap gs :<c-u>call Search(visualmode())<cr>
-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 <silent> cog :call Cycle_searchprg()<cr>
+nmap <silent> gs :set opfunc=My_search<cr>g@
+xmap <silent> gs :call Search(visualmode())<cr>
+
+" nmap gs :let g:my_searchprg="Grep"<cr>:set opfunc=My_search<cr>g@
+" nmap g/ :let g:my_searchprg="GitGrep"<cr>:set opfunc=My_search<cr>g@
+" xmap gs :<c-u>let g:my_searchprg="Grep"<cr>:call Search(visualmode())<cr>
+" xmap g/ :<c-u>let g:my_searchprg="GitGrep"<cr>:call Search(visualmode())<cr>