Sink in quickfix with filename & linenum from fzf#vim#grep
- Category
- [x] Question
- [ ] Bug
- [ ] Suggestion
- OS
- [x] Linux
- [ ] macOS
- [ ] Windows
- [ ] Etc.
- Vim
- [ ] Vim
- [x] Neovim
I'd like to populate the quickfix list with line number from the output of a fzf#vim#grep command.
I'm using the command:
command! -bang FLines call fzf#vim#grep(
\'grep -vnITr --color=always "^$"',
\ 0,
\ {'options': '--reverse --prompt "FLines> "'})
to recursively grep all lines within the pwd. Therefore, I need to populate the quickfix list with both filepath and line number to accurately jump to the search results.
I tried to implement something similar in this comment, but I failed to get anywhere. For some reason, I can't do any introspection while inside build_quickfix_list: I can't echo or assign to a global variable to try to figure out how to break up a:lines in setqflist:
function! s:build_quickfix_list(lines)
echom a:lines " Does not work?
let g:tml_variable = cope(a:lines) " Does not work?
" TODO: split a:lines between filename, linenum and text
call setqflist(map(copy(a:lines), '{ "filename": v:val, "lnum": <?>, "text": <?> }'))
copen
cc
endfunction
- Why can't I echo / set global vars from this function?
- Am I on the right track to set the quickfix list with filepath/linenum?
I want this exactly! Has anyone figured out how to do this?
I hope this helps: this action calls this function to populate the quickfix list with selected items from fzf results.
This is written in lua, however it can be easily translated to VimL.
Why can't I echo / set global vars from this function?
By "can't" you mean what? Most likely s:build_quickfix_list doesn't get called. And if you pass a command, it receives only the first filename. But actually what you want works out of the box. You do :Rg [PATTERN], optionally filter the results, press Alt-A to select all the lines, then Enter, and a quickfix list with the results appears. It doesn't appear if you select only one line.