From fce46ed7e852dfc60466c50f348c0c2c7caba7fc Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Tue, 10 Aug 2021 10:32:16 +0200 Subject: Minor change --- vim/.vim/plugin/search.vim | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 vim/.vim/plugin/search.vim (limited to 'vim/.vim/plugin') diff --git a/vim/.vim/plugin/search.vim b/vim/.vim/plugin/search.vim new file mode 100644 index 0000000..b4e1054 --- /dev/null +++ b/vim/.vim/plugin/search.vim @@ -0,0 +1,52 @@ +" http://vim.wikia.com/wiki/Searching_for_files +function! MySearch(...) + let l:prevgrepprg=&grepprg + let l:prevgrepformat=&grepformat + if a:1 == "Rg" + set grepprg=rg\ -uu\ --vimgrep + set grepformat=%f:%l:%c:%m + elseif a:1 == "Gnufind" + set grepprg=find\ .\ -name + set grepformat=%f + elseif a:1 == "Gitfind" + set grepprg=git\ ls-files\ -i\ -x + set grepformat=%f + endif + execute 'silent grep!' a:2 | cwindow | redraw! + let &grepprg=l:prevgrepprg + let &grepformat=l:prevgrepformat +endfun + +command! -nargs=+ -complete=file_in_path Rg call MySearch("Rg", ) +command! -nargs=+ -complete=file_in_path Gnufind call MySearch("Gnufind", ) +command! -nargs=+ -complete=file_in_path Gitfind call MySearch("Gitfind", ) +command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' | cw | redraw! +command! -nargs=+ -complete=file_in_path VimGrep execute 'silent vimgrep!' | cw | redraw! + +" Default search and find programs +function! FillSearch(...) + if a:0 == 0 + let l:filltext = "" + else + let l:is_visual=(a:1 == "v") + let l:line=getline(l:is_visual ? "'<" : "'[") + let [line1,col1] = getpos(l:is_visual ? "'<" : "'[")[1:2] + let [line2,col2] = getpos(l:is_visual ? "'>" : "']")[1:2] + let l:filltext =l:line[col1 - 1: col2 - 1] + endif + call feedkeys(':' . g:my_fillprg . ' "' . l:filltext . '"'."\") +endfunction + +let g:my_searchprgs = ['Rg', 'GitGrep', 'VimGrep'] +let g:my_findprgs = ['Gnufind', 'Gitfind'] +let g:my_searchprg = 0 +let g:my_findprg = 0 + +nnoremap g/ :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:set opfunc=FillSearchg@ +nnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch() +xnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch(visualmode()) +nnoremap ,f :let g:my_fillprg=g:my_findprgs[g:my_findprg]:call FillSearch() + +" Cycle search / find prgs +nnoremap cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs):let &ro = &ro +nnoremap cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs):let &ro = &ro -- cgit v1.2.3