Skip to content

Instantly share code, notes, and snippets.

@davidmh
Last active July 15, 2022 20:00
Show Gist options
  • Save davidmh/f35fba1f9cde176d1ec9b4919769653a to your computer and use it in GitHub Desktop.
Save davidmh/f35fba1f9cde176d1ec9b4919769653a to your computer and use it in GitHub Desktop.
Filter the quickfix list with fzf
function! s:format_qf_line(line)
let parts = split(a:line, ':')
return { 'filename': parts[0]
\,'lnum': parts[1]
\,'col': parts[2]
\,'text': join(parts[3:], ':')
\ }
endfunction
function! s:qf_to_fzf(key, line) abort
let l:filepath = expand('#' . a:line.bufnr . ':p')
return l:filepath . ':' . a:line.lnum . ':' . a:line.col . ':' . a:line.text
endfunction
function! s:fzf_to_qf(filtered_list) abort
let list = map(a:filtered_list, 's:format_qf_line(v:val)')
if len(list) > 0
call setqflist(list)
copen
endif
endfunction
command! FzfQF call fzf#run({
\ 'source': map(getqflist(), function('<sid>qf_to_fzf')),
\ 'down': '20',
\ 'sink*': function('<sid>fzf_to_qf'),
\ 'options': '--reverse --multi --bind=ctrl-a:select-all,ctrl-d:deselect-all --prompt "quickfix> "',
\ })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment