summaryrefslogtreecommitdiff
path: root/fnl/plugins/grug-far.fnl
blob: 44da9b18e5a63d787907698b642dcc689ce59c7b (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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!"}]])

(λ 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)))

(λ visual-replace []
  (let [grug (require :grug-far)]
    (grug.with_visual_selection {:prefills {:flags (vim.fn.expand "%")}})))

(λ config []
  (let [{: create-auto-cmds} (require :util.cmds)
        grug (require :grug-far)]
    (create-auto-cmds auto-cmds)
    (grug.setup)))

(local keys [{1 :<m-r> 2 :<cmd>GrugFar<cr> :desc "Find and Replace"}
             {1 :<m-w>
              2 (λ []
                  (replace (vim.fn.expand :<cword>)))
              :desc "Find and replace word under cursor"}
             {1 :<m-x>
              2 (λ []
                  (replace nil (vim.fn.expand "%")))
              :desc "Find and replace in file"}
             {1 :<m-a>
              2 (λ []
                  (replace (vim.fn.expand :<cword>) (vim.fn.expand "%")))
              :desc "Find and replace cword in file"}
             {1 :<m-r>
              2 (λ []
                  (visual-replace))
              :desc "Find and Replace"
              :mode [:v]}])

{1 :MagicDuck/grug-far.nvim : keys : config}