aboutsummaryrefslogtreecommitdiffstats
path: root/lua/plugins/spectre.lua
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2024-12-09 10:44:18 -0300
committerElvis Claros Castro <elvis@claros.ar>2024-12-09 10:44:18 -0300
commite00fc002a6441fa3741d1f705337efbbd8850744 (patch)
treef6891a9119ee065db574aae73395af973100a008 /lua/plugins/spectre.lua
parent546d06a2314d0b4b5360346243bcfc0bda3fff30 (diff)
downloadnvim-conf-e00fc002a6441fa3741d1f705337efbbd8850744.tar.gz
nvim-conf-e00fc002a6441fa3741d1f705337efbbd8850744.zip
Cambios varios.
Diffstat (limited to 'lua/plugins/spectre.lua')
-rw-r--r--lua/plugins/spectre.lua70
1 files changed, 67 insertions, 3 deletions
diff --git a/lua/plugins/spectre.lua b/lua/plugins/spectre.lua
index 7510c7a..e3840af 100644
--- a/lua/plugins/spectre.lua
+++ b/lua/plugins/spectre.lua
@@ -1,5 +1,69 @@
+--- General configuration for spectre base on current git repo
+---@param default_opts table | nil
+---@return table
+function _G.get_spectre_options(default_opts)
+ local Path = require("utils.path")
+ local opts = default_opts or {}
+
+ if Path.is_git_repo() then
+ opts.cwd = Path.get_git_root()
+ end
+
+ return opts
+end
+
return {
- "nvim-pack/nvim-spectre",
- keys = { { "<leader>F", ":Spectre<cr>", desc = "Spectre Search open" } },
- config = true,
+ { "MagicDuck/grug-far.nvim", enabled = false },
+ {
+ -- Search and replace with pattern
+ "nvim-pack/nvim-spectre",
+ cmd = "Spectre",
+ opts = { open_cmd = "noswapfile vnew" },
+ keys = {
+ {
+ "<leader>sr",
+ function()
+ require("spectre").open()
+ end,
+ desc = "Replace in files",
+ },
+ {
+ "<leader>sp",
+ ":lua require('spectre').open(_G.get_spectre_options())<CR>",
+ desc = "Replace in files (Root dir)",
+ },
+ -- Search current word
+ {
+ "<leader>sP",
+ ":lua require('spectre').open_visual(_G.get_spectre_options({ select_word = true }))<CR>",
+ desc = "Replace current word (Root dir)",
+ },
+ -- Open search with select word in visual mode
+ {
+ "<leader>sr",
+ ":lua require('spectre').open_visual(_G.get_spectre_options())<CR>",
+ mode = "v",
+ silent = true,
+ desc = "Replace current word (Root dir)",
+ },
+ -- Search on current file
+ {
+ "<leader>sf",
+ ":lua require('spectre').open_file_search(_G.get_spectre_options({ select_word = true }))<CR>",
+ 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,
+ },
}