vim grep plugin


vim grep 插件

nnoremap <leader>g :set operatorfunc=<SID>GrepOperator<cr>g@
vnoremap <leader>g :<C-U>call <SID>GrepOperator(visualmode())<cr>

function! s:GrepOperator(type)
    let saved_unnamed_register = @@

    if a:type ==# 'v'
        normal! `<v`>y
    elseif a:type ==# 'char'
        normal! `[v`]y
    else
        return
    endif

    execute "grep! -R " . shellescape(@@) . " ."
    cw
    let @@ = saved_unnamed_register
endfunction

这是一个选中的东西复制,并grep找出结果,并输出到quickfix结果中