mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-22 08:45:42 +08:00
Add support for grep in loaded buffers
This commit is contained in:
parent
9ae4c3e476
commit
fa9214cd49
@ -172,8 +172,9 @@ function! SpaceVim#mapping#space#init() abort
|
|||||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'S'], "execute 'Unite grep:%::' . expand(\"<cword>\") . ' -start-insert'",
|
call SpaceVim#mapping#space#def('nnoremap', ['s', 'S'], "execute 'Unite grep:%::' . expand(\"<cword>\") . ' -start-insert'",
|
||||||
\ 'grep cursor word in current buffer', 1)
|
\ 'grep cursor word in current buffer', 1)
|
||||||
" Searching in all loaded buffers
|
" 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'], "call SpaceVim#plugins#flygrep#open({'input' : input(\"grep pattern:\"), 'files':'@buffers'})",
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'], "execute 'Unite grep:$buffers::' . expand(\"<cword>\") . ' -start-insert'",
|
\ 'grep in all loaded buffers', 1)
|
||||||
|
call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'], "call SpaceVim#plugins#flygrep#open({'input' : expand(\"<cword>\"), 'files':'@buffers'})",
|
||||||
\ 'grep cursor word in all loaded buffers', 1)
|
\ 'grep cursor word in all loaded buffers', 1)
|
||||||
" Searching in files in an arbitrary directory
|
" Searching in files in an arbitrary directory
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'], 'Unite grep', 'grep in arbitrary directory', 1)
|
call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'], 'Unite grep', 'grep in arbitrary directory', 1)
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
let s:MPT = SpaceVim#api#import('prompt')
|
let s:MPT = SpaceVim#api#import('prompt')
|
||||||
let s:JOB = SpaceVim#api#import('job')
|
let s:JOB = SpaceVim#api#import('job')
|
||||||
let s:SYS = SpaceVim#api#import('system')
|
let s:SYS = SpaceVim#api#import('system')
|
||||||
|
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||||
let s:grepid = 0
|
let s:grepid = 0
|
||||||
let s:MPT._prompt.mpt = '➭ '
|
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
|
function! SpaceVim#plugins#flygrep#open(agrv) abort
|
||||||
rightbelow split __flygrep__
|
rightbelow split __flygrep__
|
||||||
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
|
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
|
setf SpaceVimFlyGrep
|
||||||
redraw!
|
redraw!
|
||||||
let s:MPT._prompt.begin = get(a:agrv, 'input', '')
|
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()
|
call s:MPT.open()
|
||||||
let &t_ve = save_tve
|
let &t_ve = save_tve
|
||||||
endfunction
|
endfunction
|
||||||
@ -100,7 +108,11 @@ function! s:get_search_cmd(exe, expr) abort
|
|||||||
if a:exe ==# 'grep'
|
if a:exe ==# 'grep'
|
||||||
return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.']
|
return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.']
|
||||||
elseif a:exe ==# 'rg'
|
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
|
else
|
||||||
return [a:exe, a:expr]
|
return [a:exe, a:expr]
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user