1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-22 20:41:32 +08:00

feat(flygrep): make flygrep support input and cwd

This commit is contained in:
Eric Wong 2025-02-15 23:44:16 +08:00
parent 15ef9c83cf
commit 5d297cec4d
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
4 changed files with 296 additions and 264 deletions

View File

@ -43,52 +43,52 @@ function! SpaceVim#mapping#space#init() abort
\ . string(s:_function('s:windows_transient_state')) . ', [])', \ . string(s:_function('s:windows_transient_state')) . ', [])',
\ ['buffer-transient-state', \ ['buffer-transient-state',
\ [ \ [
\ '[SPC w .] is to open the buffer transient state', \ '[SPC w .] is to open the buffer transient state',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'd'], 'close', call SpaceVim#mapping#space#def('nnoremap', ['w', 'd'], 'close',
\ ['close-current-windows', \ ['close-current-windows',
\ [ \ [
\ '[SPC w d] is to close current windows', \ '[SPC w d] is to close current windows',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'f'], 'setlocal scrollbind!', call SpaceVim#mapping#space#def('nnoremap', ['w', 'f'], 'setlocal scrollbind!',
\ ['toggle-follow-mode', \ ['toggle-follow-mode',
\ [ \ [
\ '[SPC w f] is to toggle follow mode', \ '[SPC w f] is to toggle follow mode',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'D'], 'ChooseWin | close | wincmd w', call SpaceVim#mapping#space#def('nnoremap', ['w', 'D'], 'ChooseWin | close | wincmd w',
\ ['delete-window-(other-windows)', \ ['delete-window-(other-windows)',
\ [ \ [
\ '[SPC w D] is to select a windows to close', \ '[SPC w D] is to select a windows to close',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'F'], 'tabnew', call SpaceVim#mapping#space#def('nnoremap', ['w', 'F'], 'tabnew',
\ ['create-new-tab', \ ['create-new-tab',
\ [ \ [
\ '[SPC w F] is to create new tab', \ '[SPC w F] is to create new tab',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
" let s:lnum = expand('<slnum>') + s:funcbeginline " let s:lnum = expand('<slnum>') + s:funcbeginline
" call SpaceVim#mapping#space#def('nnoremap', ['w', 'F'], 'call call(' " call SpaceVim#mapping#space#def('nnoremap', ['w', 'F'], 'call call('
" \ . string(function('s:create_new_named_tab')) " \ . string(function('s:create_new_named_tab'))
@ -105,216 +105,216 @@ function! SpaceVim#mapping#space#init() abort
call SpaceVim#mapping#space#def('nnoremap', ['w', 'h'], 'wincmd h', call SpaceVim#mapping#space#def('nnoremap', ['w', 'h'], 'wincmd h',
\ ['window-left', \ ['window-left',
\ [ \ [
\ '[SPC w h] is to jump to the left window', \ '[SPC w h] is to jump to the left window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'j'], 'wincmd j', call SpaceVim#mapping#space#def('nnoremap', ['w', 'j'], 'wincmd j',
\ ['window-down', \ ['window-down',
\ [ \ [
\ '[SPC w j] is to jump to the window below current windows', \ '[SPC w j] is to jump to the window below current windows',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'x'], 'wincmd x', call SpaceVim#mapping#space#def('nnoremap', ['w', 'x'], 'wincmd x',
\ ['window-switch-placement', \ ['window-switch-placement',
\ [ \ [
\ '[SPC w x] is to jump to exchange current window with next one.', \ '[SPC w x] is to jump to exchange current window with next one.',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'k'], 'wincmd k', call SpaceVim#mapping#space#def('nnoremap', ['w', 'k'], 'wincmd k',
\ ['window-up', \ ['window-up',
\ [ \ [
\ '[SPC w k] is to jump to the window above current windows', \ '[SPC w k] is to jump to the window above current windows',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'l'], 'wincmd l', call SpaceVim#mapping#space#def('nnoremap', ['w', 'l'], 'wincmd l',
\ ['window-right', \ ['window-right',
\ [ \ [
\ '[SPC w l] is to jump to the right window', \ '[SPC w l] is to jump to the right window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'H'], 'wincmd H', call SpaceVim#mapping#space#def('nnoremap', ['w', 'H'], 'wincmd H',
\ ['window-far-left', \ ['window-far-left',
\ [ \ [
\ '[SPC w H] is to jump to the far left window', \ '[SPC w H] is to jump to the far left window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'J'], 'wincmd J', call SpaceVim#mapping#space#def('nnoremap', ['w', 'J'], 'wincmd J',
\ ['window-far-down', \ ['window-far-down',
\ [ \ [
\ '[SPC w J] is to jump to the far down window', \ '[SPC w J] is to jump to the far down window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'K'], 'wincmd K', call SpaceVim#mapping#space#def('nnoremap', ['w', 'K'], 'wincmd K',
\ ['window-far-up', \ ['window-far-up',
\ [ \ [
\ '[SPC w K] is to jump to the far up window', \ '[SPC w K] is to jump to the far up window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'L'], 'wincmd L', call SpaceVim#mapping#space#def('nnoremap', ['w', 'L'], 'wincmd L',
\ ['window-far-right', \ ['window-far-right',
\ [ \ [
\ '[SPC w L] is to jump to the far right window', \ '[SPC w L] is to jump to the far right window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'm'], 'call call(' call SpaceVim#mapping#space#def('nnoremap', ['w', 'm'], 'call call('
\ . string(function('s:maximize_minimize_win')) \ . string(function('s:maximize_minimize_win'))
\ . ', [])', \ . ', [])',
\ ['maximize/minimize window', \ ['maximize/minimize window',
\ [ \ [
\ '[SPC w m] is to maximize/minimize window', \ '[SPC w m] is to maximize/minimize window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'M'], call SpaceVim#mapping#space#def('nnoremap', ['w', 'M'],
\ "execute eval(\"winnr('$')<=2 ? 'wincmd x' : 'ChooseWinSwap'\")", \ "execute eval(\"winnr('$')<=2 ? 'wincmd x' : 'ChooseWinSwap'\")",
\ ['swap window', \ ['swap window',
\ [ \ [
\ '[SPC w M] is to swap window', \ '[SPC w M] is to swap window',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'o'], 'tabnext', call SpaceVim#mapping#space#def('nnoremap', ['w', 'o'], 'tabnext',
\ ['other-tabs', \ ['other-tabs',
\ [ \ [
\ '[SPC w o] is to switch to next tabs', \ '[SPC w o] is to switch to next tabs',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', '/'], 'belowright vsplit | wincmd w', call SpaceVim#mapping#space#def('nnoremap', ['w', '/'], 'belowright vsplit | wincmd w',
\ ['split-windows-right', \ ['split-windows-right',
\ [ \ [
\ '[SPC w /] is to split windows on the right', \ '[SPC w /] is to split windows on the right',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'v'], 'belowright vsplit | wincmd w', call SpaceVim#mapping#space#def('nnoremap', ['w', 'v'], 'belowright vsplit | wincmd w',
\ ['split-windows-right', \ ['split-windows-right',
\ [ \ [
\ '[SPC w v] is to split windows on the right', \ '[SPC w v] is to split windows on the right',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', '-'], 'bel split | wincmd w', call SpaceVim#mapping#space#def('nnoremap', ['w', '-'], 'bel split | wincmd w',
\ ['split-windows-below', \ ['split-windows-below',
\ [ \ [
\ '[SPC w -] is to split windows below', \ '[SPC w -] is to split windows below',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 's'], 'bel split | wincmd w', call SpaceVim#mapping#space#def('nnoremap', ['w', 's'], 'bel split | wincmd w',
\ ['split-windows-below', \ ['split-windows-below',
\ [ \ [
\ '[SPC w s] is to split windows below', \ '[SPC w s] is to split windows below',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'S'], 'bel split', call SpaceVim#mapping#space#def('nnoremap', ['w', 'S'], 'bel split',
\ ['split-focus-windows-below', \ ['split-focus-windows-below',
\ [ \ [
\ '[SPC w S] is to split windows below and focus on new windows', \ '[SPC w S] is to split windows below and focus on new windows',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', '2'], 'silent only | vs | wincmd w', call SpaceVim#mapping#space#def('nnoremap', ['w', '2'], 'silent only | vs | wincmd w',
\ ['layout-double-columns', \ ['layout-double-columns',
\ [ \ [
\ '[SPC w 2] is to change current windows layout to double columns', \ '[SPC w 2] is to change current windows layout to double columns',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', '3'], 'silent only | vs | vs | wincmd H', call SpaceVim#mapping#space#def('nnoremap', ['w', '3'], 'silent only | vs | vs | wincmd H',
\ ['layout-three-columns', \ ['layout-three-columns',
\ [ \ [
\ '[SPC w 3] is to change current windows layout to three columns', \ '[SPC w 3] is to change current windows layout to three columns',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', 'V'], call SpaceVim#mapping#space#def('nnoremap', ['w', 'V'],
\ 'bel vs', \ 'bel vs',
\ ['split-window-right-focus', \ ['split-window-right-focus',
\ [ \ [
\ '[SPC w V] is to split window on the right', \ '[SPC w V] is to split window on the right',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['w', '='], call SpaceVim#mapping#space#def('nnoremap', ['w', '='],
\ 'wincmd =', \ 'wincmd =',
\ ['balance-windows', \ ['balance-windows',
\ [ \ [
\ '[SPC w =] is to balance all the windows in current tab', \ '[SPC w =] is to balance all the windows in current tab',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ], 1) \ ], 1)
call SpaceVim#mapping#space#def('nnoremap', ['w', 'w'], call SpaceVim#mapping#space#def('nnoremap', ['w', 'w'],
\ 'wincmd w', 'cycle and focus between windows', 1) \ 'wincmd w', 'cycle and focus between windows', 1)
call SpaceVim#mapping#space#def('nnoremap', ['w', 'W'], call SpaceVim#mapping#space#def('nnoremap', ['w', 'W'],
@ -326,14 +326,14 @@ function! SpaceVim#mapping#space#init() abort
\ . string(function('s:next_buffer')) \ . string(function('s:next_buffer'))
\ . ', [])', ['next-buffer', \ . ', [])', ['next-buffer',
\ [ \ [
\ '[SPC b n] is running :bnext, jump to next buffer', \ '[SPC b n] is running :bnext, jump to next buffer',
\ 'which is a vim build in command', \ 'which is a vim build in command',
\ 'It is bound to SPC b n, ] b,', \ 'It is bound to SPC b n, ] b,',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 's'], call SpaceVim#mapping#space#def('nnoremap', ['b', 's'],
\ 'call call(' \ 'call call('
\ . string(function('s:switch_scratch_buffer')) \ . string(function('s:switch_scratch_buffer'))
@ -343,14 +343,14 @@ function! SpaceVim#mapping#space#init() abort
\ . string(function('s:previous_buffer')) \ . string(function('s:previous_buffer'))
\ . ', [])', ['previous-buffer', \ . ', [])', ['previous-buffer',
\ [ \ [
\ 'SPC b p is running :bp, jump to previous buffer', \ 'SPC b p is running :bp, jump to previous buffer',
\ 'which is a vim build in command', \ 'which is a vim build in command',
\ 'It is bound to SPC b p, [ b,', \ 'It is bound to SPC b p, [ b,',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
if g:spacevim_relativenumber if g:spacevim_relativenumber
nnoremap <silent> [SPC]tn :<C-u>setlocal nonumber! norelativenumber!<CR> nnoremap <silent> [SPC]tn :<C-u>setlocal nonumber! norelativenumber!<CR>
@ -371,13 +371,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-in-current-buffer', \ ['grep-in-current-buffer',
\ [ \ [
\ 'SPC s s will search text in current buffer, an input promot will be opened.', \ 'SPC s s will search text in current buffer, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'S'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'S'],
@ -386,13 +386,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-cword-in-current-buffer', \ ['grep-cword-in-current-buffer',
\ [ \ [
\ 'SPC s S will search the word under cursor within current buffer, an input promot will be opened.', \ 'SPC s S will search the word under cursor within current buffer, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
" Searching in all loaded buffers " Searching in all loaded buffers
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'b'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'b'],
@ -401,13 +401,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-in-all-buffers', \ ['grep-in-all-buffers',
\ [ \ [
\ 'SPC s b will search text in all loaded buffers, an input promot will be opened.', \ 'SPC s b will search text in all loaded buffers, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'],
@ -416,13 +416,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-cword-in-all-buffers', \ ['grep-cword-in-all-buffers',
\ [ \ [
\ 'SPC s B will search cursor word in all loaded buffers, an input promot will be opened.', \ 'SPC s B will search cursor word in all loaded buffers, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
" Searching in buffer directory " Searching in buffer directory
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'd'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'd'],
@ -431,13 +431,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-in-buffer-directory', \ ['grep-in-buffer-directory',
\ [ \ [
\ 'SPC s d will search text in buffer directory, an input promot will be opened.', \ 'SPC s d will search text in buffer directory, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'D'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'D'],
\ 'call SpaceVim#plugins#flygrep#open(' \ 'call SpaceVim#plugins#flygrep#open('
@ -445,13 +445,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-cword-in-buffer-directory', \ ['grep-cword-in-buffer-directory',
\ [ \ [
\ 'SPC s d will search cursor word in buffer directory, an input promot will be opened.', \ 'SPC s d will search cursor word in buffer directory, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
" Searching in files in an arbitrary directory " Searching in files in an arbitrary directory
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'],
@ -460,13 +460,13 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-in-arbitrary-directory', \ ['grep-in-arbitrary-directory',
\ [ \ [
\ 'SPC s f will search text in arbitrary directory, an input promot will be opened.', \ 'SPC s f will search text in arbitrary directory, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
let s:lnum = expand('<slnum>') + s:funcbeginline let s:lnum = expand('<slnum>') + s:funcbeginline
call SpaceVim#mapping#space#def('nnoremap', ['s', 'F'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'F'],
\ 'call SpaceVim#plugins#flygrep#open(' \ 'call SpaceVim#plugins#flygrep#open('
@ -474,21 +474,27 @@ function! SpaceVim#mapping#space#init() abort
\ . ')', \ . ')',
\ ['grep-cword-in-arbitrary-directory', \ ['grep-cword-in-arbitrary-directory',
\ [ \ [
\ 'SPC s F will search cursor world in arbitrary directory, an input promot will be opened.', \ 'SPC s F will search cursor world in arbitrary directory, an input promot will be opened.',
\ 'The default searching tool is based on search_tools option', \ 'The default searching tool is based on search_tools option',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
" Searching in project " Searching in project
call SpaceVim#mapping#space#def('nnoremap', ['s', 'p'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'p'],
\ 'call SpaceVim#plugins#flygrep#open(' . \ 'call SpaceVim#plugins#flygrep#open(' .
\ "{'input' : input(\"grep pattern:\"), 'dir' : get(b:, \"rootDir\", getcwd())})", \ "{'input' : input(\"grep pattern:\"), 'dir' : get(b:, \"rootDir\", getcwd())})",
\ 'grep-in-project', 1) \ 'grep-in-project', 1)
call SpaceVim#mapping#space#def('nnoremap', ['s', 'P'], if g:spacevim_flygrep_next_version && has('nvim-0.10.0')
\ "call SpaceVim#plugins#flygrep#open({'input' : expand(\"<cword>\"), 'dir' : get(b:, \"rootDir\", getcwd())})", call SpaceVim#mapping#space#def('nnoremap', ['s', 'P'],
\ 'grep-cword-in-project', 1) \ "lua require('flygrep').open({input = vim.fn.expand('<cword>')})",
\ 'grep-cword-in-project', 1)
else
call SpaceVim#mapping#space#def('nnoremap', ['s', 'P'],
\ "call SpaceVim#plugins#flygrep#open({'input' : expand(\"<cword>\"), 'dir' : get(b:, \"rootDir\", getcwd())})",
\ 'grep-cword-in-project', 1)
endif
" Searching background " Searching background
if has('nvim-0.7.0') if has('nvim-0.7.0')
call SpaceVim#mapping#space#def('nnoremap', ['s', 'j'], call SpaceVim#mapping#space#def('nnoremap', ['s', 'j'],
@ -706,12 +712,12 @@ function! SpaceVim#mapping#space#init() abort
\ . string(function('s:describe_current_time')) \ . string(function('s:describe_current_time'))
\ . ', [])', ['describe-current-time', \ . ', [])', ['describe-current-time',
\ [ \ [
\ 'SPC h d t is to display current time.', \ 'SPC h d t is to display current time.',
\ '', \ '',
\ 'Definition: ' . s:file . ':' . s:lnum, \ 'Definition: ' . s:file . ':' . s:lnum,
\ ] \ ]
\ ] \ ]
\ , 1) \ , 1)
if has('nvim-0.7.0') if has('nvim-0.7.0')
call SpaceVim#mapping#space#def('nnoremap', ['a', 'o'], 'lua require("spacevim.plugin.todo").list()', 'open-todo-manager', 1) call SpaceVim#mapping#space#def('nnoremap', ['a', 'o'], 'lua require("spacevim.plugin.todo").list()', 'open-todo-manager', 1)
else else
@ -904,20 +910,20 @@ function! s:windows_transient_state() abort
call state.set_title('Buffer Selection Transient State') call state.set_title('Buffer Selection Transient State')
call state.defind_keys( call state.defind_keys(
\ { \ {
\ 'layout' : 'vertical split', \ 'layout' : 'vertical split',
\ 'left' : [ \ 'left' : [
\ ], \ ],
\ 'right' : [ \ 'right' : [
\ { \ {
\ 'key' : 'n', \ 'key' : 'n',
\ 'desc' : 'next buffer', \ 'desc' : 'next buffer',
\ 'func' : '', \ 'func' : '',
\ 'cmd' : 'bnext', \ 'cmd' : 'bnext',
\ 'exit' : 0, \ 'exit' : 0,
\ }, \ },
\ ], \ ],
\ } \ }
\ ) \ )
call state.open() call state.open()
endfunction endfunction

View File

@ -12,7 +12,7 @@
- [Intro](#intro) - [Intro](#intro)
- [Requirements](#requirements) - [Requirements](#requirements)
- [Install](#install) - [Install](#install)
- [Command](#command) - [Usage](#usage)
- [Configuration](#configuration) - [Configuration](#configuration)
- [Key Bindings](#key-bindings) - [Key Bindings](#key-bindings)
- [Feedback](#feedback) - [Feedback](#feedback)
@ -36,9 +36,12 @@
Plug 'wsdjeg/flygrep.nvim' Plug 'wsdjeg/flygrep.nvim'
``` ```
## Command ## Usage
- `:FlyGrep`: open flygrep in current directory - `:FlyGrep`: open flygrep in current directory
- `:lua require('flygrep').open(opt)`: opt supports following keys,
- cwd: root directory of searching job
- input: default input text in prompt window
## Configuration ## Configuration

View File

@ -15,9 +15,11 @@ if not ok then
ok, cmp = pcall(require, 'cmp') ok, cmp = pcall(require, 'cmp')
end end
local grep_root_dir = '.'
local grep_timer_id = -1 local grep_timer_id = -1
local grep_input = '' local grep_input = ''
local search_jobid = -1 local search_jobid = 0
local search_hi_id = -1 local search_hi_id = -1
local fix_string = false local fix_string = false
local include_hidden_file = false local include_hidden_file = false
@ -67,7 +69,7 @@ end
-- 搜索结果行转换成文件名、光标位置 -- 搜索结果行转换成文件名、光标位置
local function get_file_pos(line) local function get_file_pos(line)
local filename = vim.fn.fnameescape(vim.fn.split(line, [[:\d\+:]])[1]) local filename = vim.fn.fnamemodify(vim.fn.fnameescape(vim.fn.split(line, [[:\d\+:]])[1]), ':p')
local linenr = vim.fn.str2nr(string.sub(vim.fn.matchstr(line, [[:\d\+:]]), 2, -2)) local linenr = vim.fn.str2nr(string.sub(vim.fn.matchstr(line, [[:\d\+:]]), 2, -2))
local colum = vim.fn.str2nr(string.sub(vim.fn.matchstr(line, [[\(:\d\+\)\@<=:\d\+:]]), 2, -2)) local colum = vim.fn.str2nr(string.sub(vim.fn.matchstr(line, [[\(:\d\+\)\@<=:\d\+:]]), 2, -2))
return filename, linenr, colum return filename, linenr, colum
@ -131,6 +133,7 @@ local function grep_timer(t)
update_result_count() update_result_count()
end end
end, end,
cwd = grep_root_dir,
}) })
end end
@ -144,7 +147,7 @@ local function build_prompt_title()
table.insert(t, { ' string ', 'FlyGrep_b' }) table.insert(t, { ' string ', 'FlyGrep_b' })
end end
table.insert(t, { '', 'FlyGrep_b' }) table.insert(t, { '', 'FlyGrep_b' })
table.insert(t, { ' ' .. vim.fn.getcwd() .. ' ', 'FlyGrep_b' }) table.insert(t, { ' ' .. grep_root_dir .. ' ', 'FlyGrep_b' })
table.insert(t, { '', 'FlyGrep_b_Normal' }) table.insert(t, { '', 'FlyGrep_b_Normal' })
-- return {{}, {}, {}} -- return {{}, {}, {}}
return t return t
@ -332,8 +335,9 @@ local function open_win()
}, },
}) })
end end
vim.cmd('noautocmd startinsert') if grep_root_dir ~= vim.fn.getcwd() then
vim.cmd('cd ' .. grep_root_dir)
end
local augroup = vim.api.nvim_create_augroup('floatgrep', { local augroup = vim.api.nvim_create_augroup('floatgrep', {
clear = true, clear = true,
}) })
@ -346,9 +350,14 @@ local function open_win()
if grep_input ~= '' then if grep_input ~= '' then
pcall(vim.fn.matchdelete, search_hi_id, result_winid) pcall(vim.fn.matchdelete, search_hi_id, result_winid)
pcall(vim.fn.timer_stop, grep_timer_id) pcall(vim.fn.timer_stop, grep_timer_id)
job.stop(search_jobid) pcall(job.stop, search_jobid)
search_hi_id = search_hi_id = vim.fn.matchadd(
vim.fn.matchadd(conf.matched_higroup, grep_input:gsub('~', '\\~'), 10, -1, { window = result_winid }) conf.matched_higroup,
grep_input:gsub('~', '\\~'),
10,
-1,
{ window = result_winid }
)
grep_timer_id = vim.fn.timer_start(conf.timeout, grep_timer, { ['repeat'] = 1 }) grep_timer_id = vim.fn.timer_start(conf.timeout, grep_timer, { ['repeat'] = 1 })
else else
pcall(vim.fn.matchdelete, search_hi_id, result_winid) pcall(vim.fn.matchdelete, search_hi_id, result_winid)
@ -447,15 +456,29 @@ local function open_win()
-1, -1,
{ window = result_winid } { window = result_winid }
) )
if grep_input ~= '' then
vim.api.nvim_buf_set_lines(prompt_bufid, 0, -1, false, {grep_input})
end
vim.cmd('noautocmd startinsert!')
end end
function M.open() function M.open(opt)
if not opt then
opt = {}
end
saved_mouse_opt = vim.o.mouse saved_mouse_opt = vim.o.mouse
grep_input = opt.input or ''
if opt.cwd and vim.fn.isdirectory(opt.cwd) == 1 then
grep_root_dir = vim.fn.fnamemodify(opt.cwd, ':p')
else
grep_root_dir = vim.fn.getcwd()
end
open_win() open_win()
end end
function M.setup(conf) function M.setup(c)
require('flygrep.config').setup(conf) require('flygrep.config').setup(c)
end end
return M return M

View File

@ -1795,7 +1795,7 @@ This option maybe removed when `flygrep.nvim` development is done.
flygrep_next_version = true flygrep_next_version = true
``` ```
When this option is `true`, only `SPC s /` will be mapped to `:FlyGrep` command from `flygrep.nvim`. And the key binding in `flygrep.nvim` window is: When this option is `true`, `SPC s /` and `SPC s P` will use `flygrep.nvim`. And the key binding in `flygrep.nvim` window is:
| Key bindings | descretion | | Key bindings | descretion |
| ------------ | ---------------------------------- | | ------------ | ---------------------------------- |