fzf-lua
fzf-lua copied to clipboard
Mixed search modes
Thanks for this great plugin :smile:
I am wondering if it's possible to have mixed search modes. For example, searching for files and grepping at the same time; or looking for lsp references but have grepping as fallback.
Ty @yshui!
Funny meeting you here after a long time since our initial encounter in picom#361 :-)
I am wondering if it's possible to have mixed search modes. For example, searching for files and grepping at the same time; or looking for lsp references but have grepping as fallback.
Not sure if I fully understand the workflow but between writing a small lua extension and using fzf's own ever-expanding tools I'm sure we can craft something to meet your needs.
searching for files and grepping at the same time
I'm assuming you mean selecting file(s) and then switching to grep mode and grep'ing only the selected files?
While not exactly what you're after you can use live_grep_glob
to regex search specific file globs, for example input of ^foo -- *.bar
will search for lines that start withfoo
only in files that have a .bar
extension, after that you can press <C-g>
to switch to fuzzy search mode and further refine the result set returned from live_grep_glob
(the process can continue endlessly).
looking for lsp references but have grepping as fallback
This is pretty easy to do, you can write a small custom action that would take the last search term and feed it into grep
, for exmaple, the below starts with lsp_document_symbols
and switches to grep when pressing <C-f>
(notice that you can then press <C-g>
to switch back to live_grep
and modify the underlying grep search term).
local fzf_lua = require'fzf-lua'
fzf_lua.lsp_workspace_symbols({
actions = {
['ctrl-f'] = function(selected, opts)
fzf_lua.grep({ search = fzf_lua.config.__resume_data.last_query })
end
}
})
Funny meeting you here after a long time since our initial encounter in https://github.com/yshui/picom/pull/361 :-)
Good memories :laughing:
Thanks for the explanation but I think it's somewhat different from what I had in mind.
I'm assuming you mean selecting file(s) and then switching to grep mode and grep'ing only the selected files?
Maybe this use case is too niche, but sometimes I find myself unsure whether to search for a file name or for a keyword. It's sometimes convenient to do both at the same time, even if I ended up don't need the result of grepping.
Similar reasoning goes for the grepping + lsp use case.
In general, I was wondering if there is a need for doing several different kinds of searches at the same time, not just limited to the examples I gave.
Yeah, being able to switch search type with a key binding is pretty neat. It helps with my problem but I still think mixed search mode would be better.
Maybe this use case is too niche, but sometimes I find myself unsure whether to search for a file name or for a keyword. It's sometimes convenient to do both at the same time, even if I ended up don't need the result of grepping.
TBH, I do think it’s a bit niche, nevertheless, if you’re willing to do a bit of legwork, it’s possible, you’d have to create your own provider (easy using the API) that combines both sources, in your case files using fd
or rg --files
plus the grep results.
An example of how to combine two result sets together can be seen in #485. If you do choose to go down this road, I’d be more than happy to help.
Closing for now, feel free to open if you more help.