From f4b191ddafcf00d0d124a1e8ab4350d1ee2b3291 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Mon, 18 Apr 2022 01:14:00 +0800 Subject: Change back to fzf and improve quickfix (vim) --- .vim/after/plugin/fzf.vim | 91 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 24 deletions(-) (limited to '.vim/after/plugin') diff --git a/.vim/after/plugin/fzf.vim b/.vim/after/plugin/fzf.vim index 9234eb4..3c7d03d 100644 --- a/.vim/after/plugin/fzf.vim +++ b/.vim/after/plugin/fzf.vim @@ -1,24 +1,67 @@ -" if executable('fzf') && get(g:, 'loaded_fzf_vim', 0) == 1 -" let g:fzf_command_prefix = 'Fzf' -" -" command! -bang -nargs=* FzfRg -" \ call fzf#vim#grep( -" \ 'rg --hidden --column --line-number --no-heading --color=always --smart-case --glob !.git -- '.shellescape(), 1, -" \ fzf#vim#with_preview(), 0) -" -" noremap ff :FzfFiles -" noremap fgf :FzfGFiles -" noremap fb :FzfBuffers -" noremap fm :FzfHistory -" noremap ft :FzfBTags -" noremap fT :FzfTags -" noremap fa :FzfAg -" noremap fr :FzfRg -" noremap fc :FzfCommands -" noremap fgc :FzfBCommits -" noremap fgC :FzfCommits -" noremap fl :FzfBLines -" noremap fL :FzfLines -" -" packadd fzf.vim -" endif +let s:fzf_default_opts = $FZF_DEFAULT_OPTS + +function! s:build_quickfix_list(lines) abort + call setqflist(map(copy(a:lines), '{ "filename": v:val }')) + copen + cc +endfunction + +function! s:format_qf_line(line) abort + let parts = split(a:line, ':') + return { + \ 'filename': parts[0], + \ 'lnum': parts[1], + \ 'col': parts[2], + \ 'text': join(parts[3:], ':') + \ } +endfunction + +function! s:fzf_qf(key, line) abort + let filepath = expand('#' . a:line.bufnr . ':p') + return filepath . ':' . a:line.lnum . ':' . a:line.col . ':' . a:line.text +endfunction + +" TODO make it accept multiple lines +function! s:fzf_qf_sink(line) abort + let line = s:format_qf_line(a:line[0]) + execute 'edit +' . line.lnum . ' ' . line.filename +endfunction + +command! FzfQuickFix call fzf#run({ + \ 'source': map(getqflist(), function('s:fzf_qf')), + \ 'down': 20, + \ 'sink*': function('s:fzf_qf_sink'), + \ 'options': s:fzf_default_opts. ' --multi --prompt "QuickFix> "' + \ }) + +if executable('fzf') && get(g:, 'loaded_fzf', 0) == 1 + let g:fzf_command_prefix = 'Fzf' + + command! -bang -nargs=* FzfRg + \ call fzf#vim#grep( + \ 'rg --hidden --column --line-number --no-heading --color=always --smart-case --glob !.git '.shellescape(), 1, + \ fzf#vim#with_preview(), 0) + + noremap ff :FzfFiles + noremap fgf :FzfGFiles + noremap fb :FzfBuffers + noremap fm :FzfHistory + noremap ft :FzfBTags + noremap fT :FzfTags + noremap fa :FzfAg + noremap fr :FzfRg + noremap fc :FzfCommands + noremap fgc :FzfBCommits + noremap fgC :FzfCommits + noremap fl :FzfBLines + noremap fL :FzfLines + noremap fq :FzfQuickFix + + let g:fzf_action = { + \ 'ctrl-q': function('s:build_quickfix_list') + \ } + let g:fzf_layout = { 'down': '40%' } + let g:fzf_preview_window = [ 'right:80%:hidden', 'ctrl-/' ] + + packadd fzf.vim +endif -- cgit v1.2.3