diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index b891d1a26..4fa8b5556 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -207,6 +207,9 @@ function! s:next_item() abort else normal! j endif + if s:preview_able == 1 + call s:preview() + endif redrawstatus call s:MPT._build_prompt() endfunction @@ -217,6 +220,9 @@ function! s:previous_item() abort else normal! k endif + if s:preview_able == 1 + call s:preview() + endif redrawstatus call s:MPT._build_prompt() endfunction @@ -272,6 +278,27 @@ function! s:move_cursor() abort call s:MPT._build_prompt() endfunction +let s:preview_able = 0 +function! s:toggle_preview() abort + if s:preview_able == 0 + let s:preview_able = 1 + call s:preview() + else + pclose + let s:preview_able = 0 + endif + redraw! + call s:MPT._build_prompt() +endfunction + +function! s:preview() abort + let line = getline('.') + let filename = fnameescape(split(line, ':\d\+:')[0]) + let linenr = matchstr(line, ':\d\+:')[1:-2] + exe 'silent pedit! +' . linenr . ' ' . filename + resize 18 +endfunction + let s:MPT._function_key = { \ "\" : function('s:next_item'), \ "\" : function('s:next_item'), @@ -284,6 +311,7 @@ let s:MPT._function_key = { \ "\<2-LeftMouse>" : function('s:double_click'), \ "\" : function('s:start_filter'), \ "\" : function('s:start_replace'), + \ "\" : function('s:toggle_preview'), \ } if has('nvim')