Is there a way to use the explorer to exclusively search for folders? #2595
|
Often times when I search for a specific folder the result gets drowned out because all the folders that match my search query gets expanded. I seemingly can't use Oh, and while I'm making a post; is there a way to split the explorer? My usecase for this is that I sometimes use the explorer to go to my Downloads folder to yank a file and paste it in my project dir / somewhere else, but to do that I have to manually navigate back to it after yanking. |
Replies: 1 comment 1 reply
Yeah, I know that feeling.
-- Use `opts.picker.sources.explorer`
Snacks.explorer({
toggles = {
search_dir = "D",
},
transform = function(item, ctx)
local is_searching = ctx.picker.input.filter.meta.searching
if is_searching and ctx.picker.opts.search_dir then
return item.dir or false
end
end,
win = {
input = {
keys = {
-- NOTE: This key was previously used for the "inspect" action
["<M-d>"] = { "toggle_search_dir", mode = { "i", "n" } },
},
},
list = {
keys = {
["<M-d>"] = "toggle_search_dir",
},
},
},
})
You cannot split it, but you can change the current working directory. For example, you can create keymaps that open specific folders: Tip You can create keymaps that work only when the explorer is focused by using local explorer_show = function(cwd)
local picker = Snacks.picker.get({ source = "explorer" })[1]
if picker then
picker:set_cwd(cwd)
picker:refresh()
else
picker = Snacks.explorer({ cwd = cwd })
end
end
vim.keymap.set("n", "<F1>", function()
explorer_show("~")
end)
vim.keymap.set("n", "<F2>", function()
explorer_show("~/Downloads")
end) |
Yeah, I know that feeling.
You cannot split it, b…