I'd like to search for a regex using Ag
. This results in more than 1000 findings. I'd like to save these findings in a buffer to be able to go through them slowly
-
1To me this is a duplicate of this question– statoxCommented Sep 2, 2020 at 8:33
-
1@statox could be. We also have a Q somewhere about filtering the quickfix list (vi.stackexchange.com/q/6511/10604, for example)– D. Ben Knoble ♦Commented Sep 2, 2020 at 12:58
1 Answer
Check :h fzf-examples
:
" An action can be a reference to a function that processes selected lines
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
let $FZF_DEFAULT_OPTS = '--bind ctrl-a:select-all'
Having this you can select all candidates with ctrl-a
and press ctrl-q
to put them into quickfix. And if needed copy/paste lines from there to a new buffer.
PS, I have actually tried to directly populate a new buffer but couldn't do it. Filled an issue to clarify this https://github.com/junegunn/fzf/issues/2164
PPS, found in source code that for grep-like fzf (grep, ag, rg) selected multiple lines are put into quickfix. So you don't need to provide ctrl-q
to g:fzf_action
just $FZF_DEFAULT_OPTS
to select all candidates then select and press Enter
.