Live filter files picker to subdirectory? #1402
-
I've customized the files picker to include directories in the search results. Is there a way to to set up an action that updates the files picker to search within the selected subdirectory? This sort of works: ["ctrl-f"] = function(selected)
local relative_path = require("fzf-lua.path").entry_to_file(selected[1]).stripped
vim.api.nvim_input("<esc>")
require("fzf-lua").files({ cwd = vim.fs.joinpath(vim.env.PWD, relative_path) })
end, But I end up in normal mode and this error is displayed:
The error refers to an auto-command I have configured in a different file (for some reason): vim.api.nvim_create_autocmd("FileType", {
desc = "restore cursor position",
group = group,
callback = function()
local exclude = { "diff", "gitcommit", "gitrebase" }
if vim.tbl_contains(exclude, vim.bo.filetype) then
return
end
local position_line = vim.api.nvim_buf_get_mark(0, [["]])[1]
if position_line >= 1 and position_line <= vim.api.nvim_buf_line_count(0) then
vim.cmd.normal({ -- line 38
bang = true,
args = { [[g`"]] },
})
end
end,
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Fzf-Lua sets the file type to fzf so it also triggers the auto command, you should probably add it to the exclude list. Another option is to reuse the existing fzf-lua windows by wrapping the action in ["ctrl-f"] = { function(selected)
local relative_path = require("fzf-lua.path").entry_to_file(selected[1]).stripped
-- this line won’t be needed
-- vim.api.nvim_input("<esc>")
require("fzf-lua").files({ cwd = vim.fs.joinpath(vim.env.PWD, relative_path) })
end }, |
Beta Was this translation helpful? Give feedback.
Fzf-Lua sets the file type to fzf so it also triggers the auto command, you should probably add it to the exclude list.
Another option is to reuse the existing fzf-lua windows by wrapping the action in
{}
: