refactor(pack): 合并 grug-far 键位并支持 visual 选中文本预填充

This commit is contained in:
xfy 2026-06-12 18:14:34 +08:00
parent 81f2a8d4cb
commit f21e467b88

View File

@ -100,7 +100,7 @@ vim.api.nvim_create_autocmd("VimEnter", {
once = true, once = true,
callback = function() callback = function()
require("mini.icons").setup() require("mini.icons").setup()
lazy._loaded["icons"] = true lazy.track("icons")
end, end,
}) })
@ -201,17 +201,19 @@ local function open_grug_far()
local grug = require("grug-far") local grug = require("grug-far")
-- 根据当前文件扩展名预填充文件过滤器 -- 根据当前文件扩展名预填充文件过滤器
local ext = vim.bo.buftype == "" and vim.fn.expand("%:e") local ext = vim.bo.buftype == "" and vim.fn.expand("%:e")
grug.open({ local filesFilter = ext and ext ~= "" and "*." .. ext or nil
transient = true, local prefills = { filesFilter = filesFilter }
prefills = {
filesFilter = ext and ext ~= "" and "*." .. ext or nil, -- 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 end
-- Normal 模式和 Visual 模式均绑定 <leader>sr -- Normal 和 Visual 模式共用同一个映射,通过 mode 表一次性注册
lazy.on_keys("grugfar", "<leader>sr", "n", load_grug_far, open_grug_far, { desc = "搜索并替换" }) lazy.on_keys("grugfar", "<leader>sr", { "n", "x" }, load_grug_far, open_grug_far, { desc = "搜索并替换" })
lazy.on_keys("grugfar", "<leader>sr", "x", load_grug_far, open_grug_far, { desc = "搜索并替换" })
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- ex-colors.nvim — colorscheme 提取与优化(命令触发懒加载) -- ex-colors.nvim — colorscheme 提取与优化(命令触发懒加载)