From 52c3b26195508150a3ffaed0ba8c493f5999a519 Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Thu, 1 Feb 2018 14:10:43 +0000 Subject: [vim] Add find and git ls-files to custom search --- bin/bin/keyboard | 3 ++ vim/.vimrc | 84 +++++++++++++++++++++++++++++++++++--------------------- xinit/.xinitrc | 3 -- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/bin/bin/keyboard b/bin/bin/keyboard index ca67828..ed46c16 100755 --- a/bin/bin/keyboard +++ b/bin/bin/keyboard @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Key repeat rate +xset r rate 400 50 + # Xcape settings killall -9 xcape diff --git a/vim/.vimrc b/vim/.vimrc index 816fba5..a7a0981 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -124,11 +124,11 @@ nnoremap gd :Gdiff " Heytmux function! Call_heytmux(vm) - call feedkeys(":'[,']Heytmux ") + call feedkeys(":'[,']Heytmux! ") endfunction nmap gh :set opfunc=Call_heytmuxg@ -xmap gh :'<,'>Heytmux +xmap gh :Heytmux! " Iron let g:iron_map_defaults=0 @@ -370,42 +370,62 @@ augroup END " }}} "" My search {{{ -if executable("ag") - set grepprg=ag\ -uu\ --vimgrep - set grepformat=%f:%l:%c:%m -endif - -if executable("rg") - set grepprg=rg\ -uu\ --vimgrep - set grepformat=%f:%l:%c:%m -endif -command! -nargs=+ -complete=file_in_path Grep execute 'silent grep!' | cw | redraw! +" http://vim.wikia.com/wiki/Searching_for_files +" 1 argument: set search program and options +" 2 argument: do search +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! -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(':' . 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 = "VimGrep" - elseif g:my_searchprg == "VimGrep" - let g:my_searchprg = "Grep" +" 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 - echom g:my_searchprg + call feedkeys(':' . g:my_fillprg . ' "' . l:filltext . '"'."\") endfunction -nmap co/ :call Cycle_searchprg() -nmap g/ :set opfunc=My_searchg@ -xmap g/ :call My_search(visualmode()) +cmap setSearchMode let g:my_fillprg=g:my_searchprgs[g:my_searchprg] +cmap setFindMode let g:my_fillprg=g:my_findprgs[g:my_findprg] +nmap g/ :setSearchMode:set opfunc=FillSearchg@ +nmap ,g :setSearchMode:call FillSearch() +xmap ,g :setSearchMode:call FillSearch(visualmode()) +nmap ,f :setFindMode:call FillSearch() + +let g:my_searchprgs = ['Rg', 'GitGrep', 'VimGrep'] +let g:my_findprgs = ['Gnufind', 'Gitfind'] +let g:my_searchprg = 0 +let g:my_findprg = 0 + +" Cycle search / find prgs +nmap cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs):echom g:my_searchprgs[g:my_searchprg] +nmap cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs):echom g:my_findprgs[g:my_findprg] " }}} diff --git a/xinit/.xinitrc b/xinit/.xinitrc index 2a50932..31b6f70 100755 --- a/xinit/.xinitrc +++ b/xinit/.xinitrc @@ -1,8 +1,5 @@ #!/bin/bash -# Key repeat rate -xset r rate 400 50 - # Pulse audio /usr/bin/start-pulseaudio-x11 -- cgit v1.2.3