-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Switch picker without leaving fzf-window #974
Comments
Ty for your kind words @Bekaboo! Your request is possible but it would require a bit more involved code as you’ll need to pass the new options to the new provider.
You can access the last query with
While a bit more hacky, the last |
Hi thanks for your reply, after searching in the source code I find another function I tried them both but none of them seems to work, here is my config: local fzf = require('fzf-lua')
fzf.setup({
winopts = {
on_create = function()
vim.keymap.set('t', '<C-_>', function()
-- fzf.builtin()
-- vim.api.nvim_feedkeys('�', 'n', true)
local info_last_query = fzf.get_info().last_query
local last_query = fzf.get_last_query()
local resume_opts = fzf.config.__resume_opts
print('info_last_query: ' .. vim.inspect(info_last_query))
print('last_query: ' .. vim.inspect(last_query))
print('resume_opts: ' .. vim.inspect(resume_opts))
end, { buffer = true })
end,
},
}) All three values ( |
You’re correct The issue we have here is that you’re opening the |
Another issue I see here is that you’re using a mapping in |
The below adds the functionality you're after for all files providers, if you wish to do that for buffers as well you'd need to also configure local fzf = require('fzf-lua')
local actions = fzf.actions
fzf.setup({
actions = {
files = {
["default"] = actions.file_edit_or_qf,
["ctrl-s"] = actions.file_split,
["ctrl-v"] = actions.file_vsplit,
["ctrl-t"] = actions.file_tabedit,
["alt-q"] = actions.file_sel_to_qf,
["alt-l"] = actions.file_sel_to_ll,
["ctrl-_"] = {
function()
local opts = {
query = fzf.config.__resume_data.last_query,
cwd = fzf.config.__resume_data.opts.cwd,
}
fzf.builtin({
actions = {
["default"] = function(selected)
fzf[selected[1]](opts)
end,
}
})
end
},
},
},
})
|
Thanks, it works incredibly well! |
I encountered a similar problem, but with a slight difference. I attempted to create a finder that displays the MRU list when the query is empty, and shows the results from I wasn't sure how to handle this 'switcher' with fzf-lua, so I ended up implementing it using the vanilla junegunn/fzf, using If possible, could anyone offer me some suggestions? |
@hexh250786313, you are tryin to mix and match a “live” reload mechanism with fuzzy matching, while possible it’s a bit tricky, if we ignore for a second displaying the MRU on backspace you can change back to fuzzy with --bind "change:reload(fd …)+unbind(change)+change-prompt(fd> )+enable-search" It might be possible to create go back to the MRU on backspace with a condition that tests the query with |
@ibhagwan is it possible to achieve this kind of thing within fzf-lua? |
Not really sure what you’re asking, this is an old issue, by “this kind of thing” do you mean the OP/title or something else? Whatever the question may be it probably is possible depending on how much effort you’re willing to invest. |
@ibhagwan apologies I mean the MRU/files switch that @hexh250786313 was asking about |
@dan-cooke, my answer #974 (comment) still stands, I can also think of another solution using the libuv headless wrapper used by fzf-lua, take a look at I can think of many different approaches, all requires to make use of fzf’s |
@ibhagwan thanks so much for your helpful replies! I am quite new to Lua/Neovim plugins so I wasn't quite sure how to call the underlying fzf from neovim. I had a look at @hexh250786313 's dotfiles and I think I'm on the right track. I will post my solution in here when I'm done! |
@ibhagwan so this works great, thanks for your help vim.keymap.set('n', '<C-p>', function()
fzf.oldfiles({
prompt = 'Recently Used > ',
cwd_only = true,
keymap = {
fzf = {
-- fzf '--bind=' options
["change"] = "reload(fd)+unbind(change)+change-prompt(Files> )+enable-search",
},
}
})
end)
Just one final question - maybe unrelated. But when I switch from oldfiles to Edit: I just need to set |
That’s because the shada file isn’t written to disk when you open a file, it is online added to the shada when you exit neovim.
This is a good solution, another way would be to an autocmd that updates the shada file on |
This is great info, thanks @ibhagwan ! For any future people like me when you start a new sessions and you try find a buffer, but you havent opened it yet, you can switch to the file picker with actions = {
buffers = { -- When on :buffers, pressing <Ctrl-k> will resume with files
["ctrl-k"] = {
function()
local opts = {
query = fzf.config.__resume_data.last_query,
cwd = fzf.config.__resume_data.opts.cwd,
}
fzf.files(opts)
end
},
},
files = { -- When on :files, pressing <Ctrl-k> will resume with buffers
["ctrl-k"] = {
function()
local opts = {
query = fzf.config.__resume_data.last_query,
cwd = fzf.config.__resume_data.opts.cwd,
}
fzf.buffers(opts)
end
},
},
}, |
Ty @mangelozzi, btw, I’ve made the last query more accessible from actions: ["ctrl-k"] = function(sel, opts)
print('q:', opts.last_query)
end |
Thanks! I made it more compact with your suggestion: actions = {
buffers = { -- When on :buffers, pressing <Ctrl-Space> will resume with files
["Ctrl-Space"] = function(_, opts) fzf.files({ query=opts.last_query, cwd=opts.cwd }) end, -- _ = sel
},
files = { -- When on :files, pressing <Ctrl-Space> will resume with buffers
["Ctrl-Space"] = function(_, opts) fzf.buffers({ query=opts.last_query, cwd=opts.cwd }) end, -- _ = sel
}
}, |
Looks great @mangelozzi! |
Info
Not related
Description
First of all thanks for making such a great plugin. fzf-lua is fast, responsive, and feature-rich, I cannot use neovim without it.
I sometimes find myself using the wrong picker only after I have typed several words in the search prompt, e.g. I was meant to live grep patterns in the project but I opened fzf files picker. In this case I want to switch to the live grep picker without leaving fzf window and perserve the previous
cwd
and the contents in the search prompt, but I haven't found a good way to achieve that.Currently, I can map
<C-_>
in theon_create
callback tofzf.builtin
to switch picker without leaving fzf window, like this:But this method has two drawbacks:
Could you please give me some hints or guidance on how to achieve this? Thanks!
The text was updated successfully, but these errors were encountered: