From 6af145077a1fdb279c7ef2c264cdc70789c6fce1 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 22 Jul 2024 00:48:44 +0200 Subject: Replace spectre with grug-far --- fnl/plugins/grug-far.fnl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 fnl/plugins/grug-far.fnl (limited to 'fnl/plugins/grug-far.fnl') diff --git a/fnl/plugins/grug-far.fnl b/fnl/plugins/grug-far.fnl new file mode 100644 index 0000000..ed6eae1 --- /dev/null +++ b/fnl/plugins/grug-far.fnl @@ -0,0 +1,46 @@ +;; Find and replace plugin. +(local auto-cmds + [[:FileType + {:pattern [:grug-far] + :command "nnoremap q :close"}] + [:FileType {:pattern [:grug-far] :command "setlocal spell!"}]]) + +(fn replace [?cword ?file] + (let [grug (require :grug-far)] + (var opts {:prefills {}}) + (when ?cword + (set opts.prefills.search ?cword)) + (when ?file + (set opts.prefills.flags ?file)) + (grug.grug_far opts))) + +(fn visual-replace [] + (let [grug (require :grug-far)] + (grug.with_visual_selection {:prefills {:flags (vim.fn.expand "%")}}))) + +(fn config [] + (let [cmds (require :util.cmds) + grug (require :grug-far)] + (cmds.create-auto-cmds auto-cmds) + (grug.setup))) + +(local keys [{1 : 2 :GrugFar :desc "Find and Replace"} + {1 : + 2 (fn [] + (replace (vim.fn.expand :))) + :desc "Find and replace word under cursor"} + {1 : + 2 (fn [] + (replace nil (vim.fn.expand "%"))) + :desc "Find and replace in file"} + {1 : + 2 (fn [] + (replace (vim.fn.expand :) (vim.fn.expand "%"))) + :desc "Find and replace cword in file"} + {1 : + 2 (fn [] + (visual-replace)) + :desc "Find and Replace" + :mode [:v]}]) + +{1 :MagicDuck/grug-far.nvim : keys : config} -- cgit v1.2.3-70-g09d2