feat(mini-files): add split opening helpers and never‑show filter integration
This commit is contained in:
1 parent
24f40765fb
commit
cbd6528c83
1 file changed
+38
-6
@@ -13,11 +13,10 @@ local function open_at_current_file()
|
|||||||
require("mini.files").open(path)
|
require("mini.files").open(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Buffer-local <C-x>/<C-v>/<C-t> (picker convention, matches the old yazi
|
--- Open the file under cursor in a split of the target window, then close
|
||||||
--- binds): open entry under cursor in a horizontal/vertical split or new tab.
|
--- the explorer. Recipe from :h MiniFiles-examples.
|
||||||
--- Recipe from :h MiniFiles-examples.
|
---@param direction string split modifier, e.g. "belowright vertical"
|
||||||
local function map_split(buf_id, lhs, direction)
|
local function open_in_split(direction)
|
||||||
vim.keymap.set("n", lhs, function()
|
|
||||||
local mf = require "mini.files"
|
local mf = require "mini.files"
|
||||||
local entry = mf.get_fs_entry()
|
local entry = mf.get_fs_entry()
|
||||||
if entry == nil or entry.fs_type ~= "file" then return end
|
if entry == nil or entry.fs_type ~= "file" then return end
|
||||||
@@ -27,7 +26,16 @@ local function map_split(buf_id, lhs, direction)
|
|||||||
end)
|
end)
|
||||||
mf.set_target_window(new_target)
|
mf.set_target_window(new_target)
|
||||||
mf.go_in { close_on_file = true }
|
mf.go_in { close_on_file = true }
|
||||||
end, { buffer = buf_id, desc = "Open in " .. direction .. " split" })
|
end
|
||||||
|
|
||||||
|
--- Buffer-local <C-x>/<C-v>/<C-t> (picker convention, matches the old yazi binds).
|
||||||
|
local function map_split(buf_id, lhs, direction)
|
||||||
|
vim.keymap.set(
|
||||||
|
"n",
|
||||||
|
lhs,
|
||||||
|
function() open_in_split(direction) end,
|
||||||
|
{ buffer = buf_id, desc = "Open in " .. direction .. " split" }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Prompt for a name with Snacks.input and create the entry inside the
|
--- Prompt for a name with Snacks.input and create the entry inside the
|
||||||
@@ -126,6 +134,11 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
|
content = {
|
||||||
|
-- shared never_show lists (node_modules, .git, lockfiles, ...) from
|
||||||
|
-- the same module that filters the snacks pickers
|
||||||
|
filter = function(fs_entry) return not require("config.ignore_patterns").is_never_shown(fs_entry.name) end,
|
||||||
|
},
|
||||||
options = {
|
options = {
|
||||||
-- take over `nvim <dir>` / :edit <dir> from netrw
|
-- take over `nvim <dir>` / :edit <dir> from netrw
|
||||||
use_as_default_explorer = true,
|
use_as_default_explorer = true,
|
||||||
@@ -148,6 +161,25 @@ return {
|
|||||||
vim.keymap.set("n", "a", function() add_entry(false) end, { buffer = buf, desc = "Add file" })
|
vim.keymap.set("n", "a", function() add_entry(false) end, { buffer = buf, desc = "Add file" })
|
||||||
vim.keymap.set("n", "A", function() add_entry(true) end, { buffer = buf, desc = "Add directory" })
|
vim.keymap.set("n", "A", function() add_entry(true) end, { buffer = buf, desc = "Add directory" })
|
||||||
vim.keymap.set("n", "d", delete_entry, { buffer = buf, desc = "Delete entry" })
|
vim.keymap.set("n", "d", delete_entry, { buffer = buf, desc = "Delete entry" })
|
||||||
|
-- <CR>: open file in the target window (the buffer) and close the
|
||||||
|
-- explorer; on a directory it just descends
|
||||||
|
vim.keymap.set(
|
||||||
|
"n",
|
||||||
|
"<CR>",
|
||||||
|
function() require("mini.files").go_in { close_on_file = true } end,
|
||||||
|
{ buffer = buf, desc = "Open" }
|
||||||
|
)
|
||||||
|
-- `l`: descend into directories as usual, but a file opens as a
|
||||||
|
-- vertical split instead of replacing the target window
|
||||||
|
vim.keymap.set("n", "l", function()
|
||||||
|
local mf = require "mini.files"
|
||||||
|
local entry = mf.get_fs_entry()
|
||||||
|
if entry ~= nil and entry.fs_type == "file" then
|
||||||
|
open_in_split "belowright vertical"
|
||||||
|
else
|
||||||
|
mf.go_in {}
|
||||||
|
end
|
||||||
|
end, { buffer = buf, desc = "Go in (files: vsplit)" })
|
||||||
map_split(buf, "<C-x>", "belowright horizontal")
|
map_split(buf, "<C-x>", "belowright horizontal")
|
||||||
map_split(buf, "<C-v>", "belowright vertical")
|
map_split(buf, "<C-v>", "belowright vertical")
|
||||||
map_split(buf, "<C-t>", "tab")
|
map_split(buf, "<C-t>", "tab")
|
||||||
|
|||||||
Reference in new issue
Block a user