From c5a31a26f644bd5f0150272bf34eb6bc5eefcfee Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 28 May 2026 15:12:04 +0800 Subject: [PATCH] Add grug-far.nvim for search and replace - Add MagicDuck/grug-far.nvim plugin with lazy loading - Bind to sr in normal and visual mode - Auto-filter by current file extension when opening Co-Authored-By: Claude Opus 4.7 (1M context) --- lua/pack.lua | 21 +++++++++++++++++++++ nvim-pack-lock.json | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/lua/pack.lua b/lua/pack.lua index 5eeb8bf..35183bc 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -10,6 +10,7 @@ vim.pack.add({ "https://github.com/mason-org/mason.nvim", "https://github.com/stevearc/conform.nvim", "https://github.com/tpope/vim-fugitive", + "https://github.com/MagicDuck/grug-far.nvim", }, { load = false }) -- mini.starter 启动页 @@ -208,3 +209,23 @@ end) lazy.on_event("lsp", "VimEnter", "*", function() require("lsp") end) + +-- grug-far - sr 触发 +local function load_grug_far() + vim.cmd.packadd("grug-far.nvim") + require("grug-far").setup({ headerMaxWidth = 80 }) +end + +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, + }, + }) +end + +lazy.on_keys("grugfar", "sr", "n", load_grug_far, open_grug_far, { desc = "Search and Replace" }) +lazy.on_keys("grugfar", "sr", "x", load_grug_far, open_grug_far, { desc = "Search and Replace" }) diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index 3e43eac..07cadd6 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -8,6 +8,10 @@ "rev": "6cd7280adead7f586db6fccbd15d2cac7e2188b9", "src": "https://github.com/rafamadriz/friendly-snippets" }, + "grug-far.nvim": { + "rev": "5506c2f59dc9ab2ed6c233585412b24d31d51521", + "src": "https://github.com/MagicDuck/grug-far.nvim" + }, "mason.nvim": { "rev": "bb639d4bf385a4d89f478b83af4d770be05ab7eb", "src": "https://github.com/mason-org/mason.nvim"