summaryrefslogtreecommitdiff
path: root/ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/grug-far.lua
blob: 997b1a6905c0dd427d12f0ea01e9e4fb30a05eaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
return {
	"MagicDuck/grug-far.nvim",
	--- Ensure existing keymaps and opts remain unaffected
	config = function(_, opts)
		require("grug-far").setup(opts)
		vim.api.nvim_create_autocmd("FileType", {
			pattern = "grug-far",
			callback = function()
				-- Map <Esc> to quit after ensuring we're in normal mode
				vim.keymap.set({ "i", "n" }, "<Esc>", "<cmd>stopinsert | bd!<CR>", { buffer = true })
			end,
		})
	end,
	keys = {
		{
			"<leader>rc",
			function()
				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,
			mode = { "n", "v" },
			desc = "Search and Replace",
		},
	},
}