grug-far.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. local M = {
  2. "MagicDuck/grug-far.nvim",
  3. cmd = "GrugFar",
  4. keys = {
  5. { "<leader>S", "<cmd>GrugFar<CR>", desc = "GrugFar: Find and Replace" },
  6. },
  7. }
  8. M.config = function()
  9. require("grug-far").setup({
  10. -- Basic configuration
  11. minSearchLength = 2,
  12. debounceMs = 300,
  13. -- UI configuration
  14. ui = {
  15. border = "rounded",
  16. size = {
  17. width = 0.8,
  18. height = 0.8,
  19. },
  20. },
  21. -- Search configuration
  22. search = {
  23. engines = { "ripgrep", "astgrep", "astgrep-rules" },
  24. defaultEngine = "ripgrep",
  25. },
  26. -- History configuration - simplified to avoid the autoSave bug
  27. history = {
  28. enabled = true,
  29. maxEntries = 50,
  30. },
  31. -- Result configuration
  32. resultLocation = {
  33. showNumberLabel = true,
  34. },
  35. })
  36. -- Additional keybindings for enhanced functionality
  37. vim.api.nvim_create_autocmd("FileType", {
  38. group = vim.api.nvim_create_augroup("grug-far-custom-keybinds", { clear = true }),
  39. pattern = { "grug-far" },
  40. callback = function()
  41. -- Toggle --fixed-strings flag
  42. vim.keymap.set("n", "<localleader>w", function()
  43. local state = unpack(require("grug-far").get_instance(0):toggle_flags({ "--fixed-strings" }))
  44. vim.notify("grug-far: toggled --fixed-strings " .. (state and "ON" or "OFF"))
  45. end, { buffer = true, desc = "Toggle fixed strings" })
  46. -- Open result location and close grug-far
  47. vim.keymap.set("n", "<C-enter>", function()
  48. require("grug-far").get_instance(0):open_location()
  49. require("grug-far").get_instance(0):close()
  50. end, { buffer = true, desc = "Open location and close" })
  51. -- Jump back to first input
  52. vim.keymap.set("n", "<left>", function()
  53. require("grug-far").get_instance(0):goto_first_input()
  54. end, { buffer = true, desc = "Jump to first input" })
  55. -- Toggle multiline mode
  56. vim.keymap.set("n", "<localleader>m", function()
  57. local state = unpack(require("grug-far").get_instance(0):toggle_flags({ "--multiline" }))
  58. vim.notify("grug-far: toggled --multiline " .. (state and "ON" or "OFF"))
  59. end, { buffer = true, desc = "Toggle multiline mode" })
  60. end,
  61. })
  62. end
  63. return M