From f21e467b88dfa676cc737efea5ec7854ab77a74b Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 12 Jun 2026 18:14:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(pack):=20=E5=90=88=E5=B9=B6=20grug-far?= =?UTF-8?q?=20=E9=94=AE=E4=BD=8D=E5=B9=B6=E6=94=AF=E6=8C=81=20visual=20?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E6=96=87=E6=9C=AC=E9=A2=84=E5=A1=AB=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/pack.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/pack.lua b/lua/pack.lua index 8c93387..d5fd072 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -100,7 +100,7 @@ vim.api.nvim_create_autocmd("VimEnter", { once = true, callback = function() require("mini.icons").setup() - lazy._loaded["icons"] = true + lazy.track("icons") end, }) @@ -201,17 +201,19 @@ local function open_grug_far() local grug = require("grug-far") -- 根据当前文件扩展名预填充文件过滤器 local ext = vim.bo.buftype == "" and vim.fn.expand("%:e") - grug.open({ - transient = true, - prefills = { - filesFilter = ext and ext ~= "" and "*." .. ext or nil, - }, - }) + local filesFilter = ext and ext ~= "" and "*." .. ext or nil + local prefills = { filesFilter = filesFilter } + + -- Visual 模式用当前选中文本预填充搜索框;Normal 模式直接打开 + if vim.fn.mode():match("^[vV\22]$") then + grug.with_visual_selection({ prefills = prefills }) + else + grug.open({ transient = true, prefills = prefills }) + end end --- Normal 模式和 Visual 模式均绑定 sr -lazy.on_keys("grugfar", "sr", "n", load_grug_far, open_grug_far, { desc = "搜索并替换" }) -lazy.on_keys("grugfar", "sr", "x", load_grug_far, open_grug_far, { desc = "搜索并替换" }) +-- Normal 和 Visual 模式共用同一个映射,通过 mode 表一次性注册 +lazy.on_keys("grugfar", "sr", { "n", "x" }, load_grug_far, open_grug_far, { desc = "搜索并替换" }) -- --------------------------------------------------------------------------- -- ex-colors.nvim — colorscheme 提取与优化(命令触发懒加载)