diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 5c056a3a3..c463252a5 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -172,8 +172,9 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nnoremap', ['s', 'S'], "execute 'Unite grep:%::' . expand(\"\") . ' -start-insert'", \ 'grep cursor word in current buffer', 1) " Searching in all loaded buffers - call SpaceVim#mapping#space#def('nnoremap', ['s', 'b'], 'Unite grep:$buffers', 'grep in all loaded buffers', 1) - call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'], "execute 'Unite grep:$buffers::' . expand(\"\") . ' -start-insert'", + call SpaceVim#mapping#space#def('nnoremap', ['s', 'b'], "call SpaceVim#plugins#flygrep#open({'input' : input(\"grep pattern:\"), 'files':'@buffers'})", + \ 'grep in all loaded buffers', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'], "call SpaceVim#plugins#flygrep#open({'input' : expand(\"\"), 'files':'@buffers'})", \ 'grep cursor word in all loaded buffers', 1) " Searching in files in an arbitrary directory call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'], 'Unite grep', 'grep in arbitrary directory', 1) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index e9c5208df..06f386aed 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -1,9 +1,13 @@ let s:MPT = SpaceVim#api#import('prompt') let s:JOB = SpaceVim#api#import('job') let s:SYS = SpaceVim#api#import('system') +let s:BUFFER = SpaceVim#api#import('vim#buffer') let s:grepid = 0 let s:MPT._prompt.mpt = '➭ ' +" keys: +" files: files for grep, @buffers means listed buffer. +let s:grep_files = '' function! SpaceVim#plugins#flygrep#open(agrv) abort rightbelow split __flygrep__ setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber @@ -13,6 +17,10 @@ function! SpaceVim#plugins#flygrep#open(agrv) abort setf SpaceVimFlyGrep redraw! let s:MPT._prompt.begin = get(a:agrv, 'input', '') + let fs = get(a:agrv, 'files', '') + if fs ==# '@buffers' + let s:grep_files = map(s:BUFFER.listed_buffers(), 'bufname(v:val)') + endif call s:MPT.open() let &t_ve = save_tve endfunction @@ -100,7 +108,11 @@ function! s:get_search_cmd(exe, expr) abort if a:exe ==# 'grep' return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.'] elseif a:exe ==# 'rg' - return ['rg', '-n', '-i', a:expr] + if !empty(s:grep_files) && type(s:grep_files) == 3 + return ['rg', '-n', '-i', a:expr] + s:grep_files + else + return ['rg', '-n', '-i', a:expr] + endif else return [a:exe, a:expr] endif