feat(clue): 启用 mini.clue 按键提示浮窗

- VimEnter setup 注册 <Leader>/g/z/<C-w>/[ ] 触发器,配 9 组 +中文描述
- LspAttach 与 gitsigns on_attach 调 ensure_buf_triggers 兜底触发器顺序
- starter all_modules 补 clue,AGENTS.md 同步懒加载策略
This commit is contained in:
xfy 2026-06-22 10:14:05 +08:00
parent f428eee797
commit 2323c01796
4 changed files with 78 additions and 3 deletions

View File

@ -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

View File

@ -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
-- =============================================================================
-- 按下前缀键(<Leader>/g/z/<C-w>/[/])后弹出浮窗,列出后续可用键及描述。
-- 类 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 = "<Leader>" },
{ mode = { "n", "x" }, keys = "g" },
{ mode = { "n", "x" }, keys = "z" },
{ mode = "n", keys = "<C-w>" },
{ 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(),
-- <Leader> 分组描述(与 keymaps.lua / plugins/*.lua 中的映射对齐)
{ mode = "n", keys = "<Leader>f", desc = "+文件" },
{ mode = "n", keys = "<Leader>g", desc = "+Git" },
{ mode = "n", keys = "<Leader>b", desc = "+Buffer" },
{ mode = "n", keys = "<Leader>c", desc = "+代码" },
{ mode = "n", keys = "<Leader>d", desc = "+诊断" },
{ mode = "n", keys = "<Leader>s", desc = "+搜索" },
{ mode = "n", keys = "<Leader>t", desc = "+标签/终端" },
{ mode = "n", keys = "<Leader>u", desc = "+用户" },
{ mode = "n", keys = "<Leader>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,
})
-- =============================================================================
-- 独立工具(按键/命令触发懒加载)
-- =============================================================================

View File

@ -87,6 +87,13 @@ local function load_gitsigns()
end, "Diff This ~")
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "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

View File

@ -116,6 +116,7 @@ local all_modules = {
"notify",
"cmdline",
"icons",
"clue",
"pick",
"files",
"surround",