From 2323c01796adc4b072e29d84e2a9a0767571ef60 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 22 Jun 2026 10:14:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(clue):=20=E5=90=AF=E7=94=A8=20mini.clue=20?= =?UTF-8?q?=E6=8C=89=E9=94=AE=E6=8F=90=E7=A4=BA=E6=B5=AE=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - VimEnter setup 注册 /g/z//[ ] 触发器,配 9 组 +中文描述 - LspAttach 与 gitsigns on_attach 调 ensure_buf_triggers 兜底触发器顺序 - starter all_modules 补 clue,AGENTS.md 同步懒加载策略 --- AGENTS.md | 6 ++-- lua/pack.lua | 67 ++++++++++++++++++++++++++++++++++++++++- lua/plugins/git.lua | 7 +++++ lua/plugins/starter.lua | 1 + 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index c7913f9..f97d1a3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,7 @@ This is a personal Neovim configuration targeting **Neovim 0.12+**. It lives at - **Plugin manager**: Neovim 0.12+ built-in `vim.pack` (not lazy.nvim / packer). Plugins are declared in `lua/pack.lua` via `vim.pack.add({ urls }, { load = false })` and tracked in `nvim-pack-lock.json`. - **Custom lazy-loading**: `lua/lazy.lua` is a ~35-line custom framework (unrelated to lazy.nvim). It provides `load()`, `on_event()`, `on_keys()`, `on_cmd()` and tracks loaded modules in `M._loaded`. -- **Mini.nvim monorepo**: Most UI/functionality comes from the single `mini.nvim` package. Its submodules (starter, pick, extra, files, icons, notify, cmdline, completion, snippets, surround, ai, cursorword, pairs) are configured individually in `lua/pack.lua` or on-demand. +- **Mini.nvim monorepo**: Most UI/functionality comes from the single `mini.nvim` package. Its submodules (starter, pick, extra, files, icons, notify, cmdline, completion, snippets, surround, clue, ai, cursorword, pairs) are configured individually in `lua/pack.lua` or on-demand. ## File Loading Order @@ -52,13 +52,15 @@ When adding new plugins that should load lazily, use the custom framework in `lu | Trigger | Plugins / Modules | |---------------|--------------------------------------| -| `VimEnter` | treesitter, lsp, icons | +| `VimEnter` | treesitter, lsp, icons, clue | | `InsertEnter` | completion, snippets, pairs | | `BufReadPost` | gitsigns, surround, ai, cursorword | | `BufWritePre` | conform (format-on-save) | | Key press | pick, files, neogit, codediff, grugfar | | Command | ex-colors (`:ExColors`) | +Note: `clue` is set up on `VimEnter` (not via `lazy.on_keys`) because `mini.clue` must register prefix keys itself as buffer-local triggers, which is incompatible with the wrapper-mapping approach. Its buffer triggers are re-asserted on `LspAttach` and inside gitsigns' `on_attach` via `MiniClue.ensure_buf_triggers()`. + ## LSP & Formatting - **LSP servers enabled**: html, cssls, gopls, vtsls, rust_analyzer, lua_ls, taplo, svelte, dartls, kotlin_lsp diff --git a/lua/pack.lua b/lua/pack.lua index cbc482f..9451473 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -16,7 +16,7 @@ -- -- 插件列表: -- mini.nvim - 单体插件集(starter、pick、extra、files、icons、 --- notify、cmdline、completion、snippets、surround) +-- notify、cmdline、completion、snippets、surround、clue) -- friendly-snippets - 社区代码片段集合 -- nvim-treesitter - 语法树解析与高亮 -- nvim-lspconfig - LSP 客户端配置 @@ -172,6 +172,71 @@ lazy.on_event("lsp", "VimEnter", "*", function() require("plugins.lsp") end) +-- ============================================================================= +-- mini.clue — 按键提示浮窗(VimEnter 后 setup) +-- ============================================================================= +-- 按下前缀键(/g/z//[/])后弹出浮窗,列出后续可用键及描述。 +-- 类 which-key 但更轻量,且独立于 'timeoutlen'。 +-- +-- 不走 lazy.on_keys 懒加载:mini.clue 需自己把前缀键注册为 buffer-local +-- 触发器,与 on_keys 的"包装映射"机制互斥;且 setup 成本极低,无懒加载收益。 +-- +-- 时序要点(来自官方文档):触发器必须是 buffer 中最后创建的 buffer-local +-- 映射,否则会被后续 LSP/gitsigns 等的 buffer-local 映射"压住"而失灵。 +-- 这里通过 VimEnter 延迟 setup(此时全局映射已全部就位), +-- 并在 LspAttach 中调用 ensure_buf_triggers 兜底。 +vim.api.nvim_create_autocmd("VimEnter", { + once = true, + callback = function() + local ok_clue, miniclue = pcall(require, "mini.clue") + if not ok_clue then + return + end + + miniclue.setup({ + triggers = { + { mode = { "n", "x" }, keys = "" }, + { mode = { "n", "x" }, keys = "g" }, + { mode = { "n", "x" }, keys = "z" }, + { mode = "n", keys = "" }, + { mode = "n", keys = "[" }, + { mode = "n", keys = "]" }, + }, + clues = { + -- 内置前缀键描述生成器(g/z/窗口/方括号跳转) + miniclue.gen_clues.g(), + miniclue.gen_clues.z(), + miniclue.gen_clues.windows(), + miniclue.gen_clues.square_brackets(), + + -- 分组描述(与 keymaps.lua / plugins/*.lua 中的映射对齐) + { mode = "n", keys = "f", desc = "+文件" }, + { mode = "n", keys = "g", desc = "+Git" }, + { mode = "n", keys = "b", desc = "+Buffer" }, + { mode = "n", keys = "c", desc = "+代码" }, + { mode = "n", keys = "d", desc = "+诊断" }, + { mode = "n", keys = "s", desc = "+搜索" }, + { mode = "n", keys = "t", desc = "+标签/终端" }, + { mode = "n", keys = "u", desc = "+用户" }, + { mode = "n", keys = "y", desc = "+复制" }, + }, + window = { + delay = 300, -- 默认 1000ms 太慢,300ms 接近 which-key 体验 + config = { border = "rounded" }, + }, + }) + + -- LSP attach 后重新确保触发器排在最后(LSP 可能创建 buffer-local 映射) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function() + pcall(miniclue.ensure_buf_triggers) + end, + }) + + lazy.track("clue") + end, +}) + -- ============================================================================= -- 独立工具(按键/命令触发懒加载) -- ============================================================================= diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua index beb07de..8e7fdaf 100644 --- a/lua/plugins/git.lua +++ b/lua/plugins/git.lua @@ -87,6 +87,13 @@ local function load_gitsigns() end, "Diff This ~") map({ "o", "x" }, "ih", ":Gitsigns select_hunk", "Gitsigns Select Hunk") -- stylua: ignore end + + -- gitsigns 创建的 buffer-local 映射可能"压住" mini.clue 触发器, + -- 这里重新确保触发器排在最后(mini.clue 未加载时静默跳过)。 + local ok_clue, miniclue = pcall(require, "mini.clue") + if ok_clue and miniclue.ensure_buf_triggers then + miniclue.ensure_buf_triggers() + end end, }) end diff --git a/lua/plugins/starter.lua b/lua/plugins/starter.lua index 517d344..fa59958 100644 --- a/lua/plugins/starter.lua +++ b/lua/plugins/starter.lua @@ -116,6 +116,7 @@ local all_modules = { "notify", "cmdline", "icons", + "clue", "pick", "files", "surround",