--- General configuration for spectre base on current git repo ---@param default_opts table | nil ---@return table function _G.get_spectre_options(default_opts) local opts = default_opts or {} -- Check if we're in a git repository and get the root local git_root = vim.fn.system("git rev-parse --show-toplevel 2>/dev/null") if vim.v.shell_error == 0 then opts.cwd = vim.trim(git_root) end return opts end return { { "MagicDuck/grug-far.nvim", enabled = false }, { -- Search and replace with pattern "nvim-pack/nvim-spectre", cmd = "Spectre", opts = { open_cmd = "noswapfile vnew" }, keys = { { "sr", function() require("spectre").open() end, desc = "Replace in files", }, { "sp", ":lua require('spectre').open(_G.get_spectre_options())", desc = "Replace in files (Root dir)", }, -- Search current word { "sP", ":lua require('spectre').open_visual(_G.get_spectre_options({ select_word = true }))", desc = "Replace current word (Root dir)", }, -- Open search with select word in visual mode { "sr", ":lua require('spectre').open_visual(_G.get_spectre_options())", mode = "v", silent = true, desc = "Replace current word (Root dir)", }, -- Search on current file { "sf", ":lua require('spectre').open_file_search(_G.get_spectre_options({ select_word = true }))", desc = "Replace in current file", }, }, }, { "folke/edgy.nvim", optional = true, opts = function(_, opts) opts.left = opts.left or {} table.insert(opts.left, { title = "Spectre", ft = "spectre_panel", size = { width = 0.3 }, }) end, }, }