summaryrefslogtreecommitdiff
path: root/fnl/plugins/grug-far.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'fnl/plugins/grug-far.fnl')
-rw-r--r--fnl/plugins/grug-far.fnl46
1 files changed, 46 insertions, 0 deletions
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 <silent> <buffer> q :close<CR>"}]
+ [: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 :<m-r> 2 :<cmd>GrugFar<cr> :desc "Find and Replace"}
+ {1 :<m-w>
+ 2 (fn []
+ (replace (vim.fn.expand :<cword>)))
+ :desc "Find and replace word under cursor"}
+ {1 :<m-x>
+ 2 (fn []
+ (replace nil (vim.fn.expand "%")))
+ :desc "Find and replace in file"}
+ {1 :<m-a>
+ 2 (fn []
+ (replace (vim.fn.expand :<cword>) (vim.fn.expand "%")))
+ :desc "Find and replace cword in file"}
+ {1 :<m-r>
+ 2 (fn []
+ (visual-replace))
+ :desc "Find and Replace"
+ :mode [:v]}])
+
+{1 :MagicDuck/grug-far.nvim : keys : config}