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 let s:command_git_main_branch = 'git symbolic-ref --short refs/remotes/origin/HEAD' let s:command_git_patch_files_changed = 'git diff --name-only --merge-base $(' \ . s:command_git_main_branch . ')' 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 ' . , 1, \ fzf#vim#with_preview(), 0) command! FzfGitChangedFiles call fzf#run({ \ 'source': s:command_git_patch_files_changed, \ 'sink': 'e' \ }) noremap ff :FzfFiles noremap fgf :FzfGFiles noremap fb :FzfBuffers noremap fm :FzfHistory noremap ft :FzfBTags noremap fT :FzfTags noremap fr :FzfRg noremap fc :FzfCommands nnoremap fC :FzfGitChangedFiles 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