Snacks.nvim文件资源管理器异常关闭及无法聚焦问题求助
Snacks.nvim 文件资源管理器问题修复
问题描述
- 资源管理器已打开时,再次调用
Snacks.explorer()会自动关闭 - 调用
Snacks.explorer()无法自动聚焦到资源管理器窗口
修复方案
1. 修改完整配置
替换原配置中的对应部分,以下是调整后的完整配置:
{ "folke/snacks.nvim", opts = { bigfile = { enabled = true }, dashboard = { enabled = true }, explorer = { enabled = true, auto_close = false, layout = { position = "left" }, follow_file = true, tree = true, }, indent = { enabled = true }, input = { enabled = true }, picker = { sources = { explorer = { layout = { layout = {position = "left"} }, follow_file = true, tree = true, focus = "list", jump = { close = false }, auto_close = false, win = { list = { keys = { ["."] = "explorer_focus", }, }, }, }, }, }, notifier = { enabled = true }, quickfile = { enabled = true }, scope = { enabled = true }, scroll = { enabled = true }, statuscolumn = { enabled = true }, words = { enabled = true }, }, keys = { { "<leader><space>", LazyVim.pick("files"), desc = "Smart Find Files" }, { "<leader>,", function() Snacks.picker.buffers() end, desc = "Buffers" }, { "<leader>:", function() Snacks.picker.command_history() end, desc = "Command History" }, { "<leader>n", function() Snacks.picker.notifications() end, desc = "Notification History" }, { "<leader>e", function() local explorer_win = Snacks.explorer.get_win() if explorer_win and vim.api.nvim_win_is_valid(explorer_win) then vim.api.nvim_set_current_win(explorer_win) else Snacks.explorer() end end, desc = "Focus/Open File Explorer" }, { "<leader>gb", function() Snacks.picker.git_branches() end, desc = "Git Branches" }, { "<leader>gl", function() Snacks.picker.git_log() end, desc = "Git Log" }, { "<leader>gL", function() Snacks.picker.git_log_line() end, desc = "Git Log Line" }, { "<leader>gs", function() Snacks.picker.git_status() end, desc = "Git Status" }, { "<leader>gS", function() Snacks.picker.git_stash() end, desc = "Git Stash" }, { "<leader>gd", function() Snacks.picker.git_diff() end, desc = "Git Diff (Hunks)" }, { "<leader>gf", function() Snacks.picker.git_log_file() end, desc = "Git Log File" }, { "gd", function() Snacks.picker.lsp_definitions() end, desc = "Goto Definition" }, { "gD", function() Snacks.picker.lsp_declarations() end, desc = "Goto Declaration" }, { "gr", function() Snacks.picker.lsp_references() end, nowait = true, desc = "References" }, { "gI", function() Snacks.picker.lsp_implementations() end, desc = "Goto Implementation" }, { "gy", function() Snacks.picker.lsp_type_definitions() end, desc = "Goto T[y]pe Definition" }, }, }
2. 关键修改说明
- 解决自动关闭问题:通过
Snacks.explorer.get_win()判断窗口是否存在,仅在窗口不存在时调用打开方法,规避默认的toggle切换行为 - 解决聚焦问题:直接调用
vim.api.nvim_set_current_win()切换到已存在的资源管理器窗口,替代原配置中不可靠的模拟按键方式 - 增强配置稳定性:在
explorer根配置中明确设置auto_close = false,确保窗口不会被自动关闭
内容的提问来源于stack exchange,提问作者PlatinumBound
相关产品推荐
相关产品推荐

