Skip to content

Commit 619e4f9

Browse files
committed
feat(find and replace): added find and replace options
1 parent b3ad7d3 commit 619e4f9

5 files changed

Lines changed: 65 additions & 7 deletions

File tree

init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require("core.keymaps")
33
require("core.autocmds")
44
require("core.lazy")
55
require("core.dashboard")
6-
6+
require("core.search")
77
vim.api.nvim_create_autocmd("VimEnter", {
88
callback = function()
99
if vim.fn.argc() == 0 then

lazy-lock.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
{
22
"LuaSnip": { "branch": "master", "commit": "3732756842a2f7e0e76a7b0487e9692072857277" },
3-
"SchemaStore.nvim": { "branch": "main", "commit": "48dba219db5d45baad6f7491e754706f74d12676" },
3+
"SchemaStore.nvim": { "branch": "main", "commit": "806187c790d93625564708c286e16142d87a5cc9" },
44
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
55
"catppuccin": { "branch": "main", "commit": "ce8d176faa4643e026e597ae3c31db59b63cef09" },
66
"cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" },
77
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
88
"git-blame.nvim": { "branch": "main", "commit": "5c536e2d4134d064aa3f41575280bc8a2a0e03d7" },
99
"gitsigns.nvim": { "branch": "main", "commit": "5813e4878748805f1518cee7abb50fd7205a3a48" },
1010
"glow.nvim": { "branch": "main", "commit": "5d5954b2f22e109d4a6eba8b2618c5b96e4ee7a2" },
11-
"hererocks": { "branch": "master", "commit": "6265dd3bcad7bddce33a36d085b3913687007735" },
11+
"hererocks": { "branch": "master", "commit": "39479ed82540be0ff9c2746707422bfe7b792672" },
1212
"image.nvim": { "branch": "master", "commit": "446a8a5cc7a3eae3185ee0c697732c32a5547a0b" },
1313
"iron.nvim": { "branch": "master", "commit": "746414e67adcd3ad2ad5dbe6262543b55ac3f3cd" },
14-
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
14+
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },
1515
"leetcode.nvim": { "branch": "master", "commit": "fdd3f91800b3983e27bc9fcfb99cfa7293d7f11a" },
1616
"lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" },
17-
"mason-lspconfig.nvim": { "branch": "main", "commit": "c55bd8a8fb191e24176c206a7af1dd51ce7276a5" },
17+
"mason-lspconfig.nvim": { "branch": "main", "commit": "3b3571b4dadbcb464804466e9872e7246c316af7" },
1818
"mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" },
1919
"noice.nvim": { "branch": "main", "commit": "7bfd942445fb63089b59f97ca487d605e715f155" },
2020
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
2121
"null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" },
2222
"nvim-cmp": { "branch": "main", "commit": "d97d85e01339f01b842e6ec1502f639b080cb0fc" },
2323
"nvim-dap": { "branch": "master", "commit": "5860c7c501eb428d3137ee22c522828d20cca0b3" },
24-
"nvim-lspconfig": { "branch": "master", "commit": "f3979663c9c8cd9ad258344b9cfb5ad83cff61c1" },
24+
"nvim-lspconfig": { "branch": "master", "commit": "c4f67bf85b01a57e3c130352c0a0e453ab8cd5b9" },
2525
"nvim-navic": { "branch": "master", "commit": "7d914a39a1ef8f4e22c2c4381abeef7c556f5a13" },
2626
"nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" },
27+
"nvim-spectre": { "branch": "master", "commit": "72f56f7585903cd7bf92c665351aa585e150af0f" },
2728
"nvim-tree.lua": { "branch": "master", "commit": "eb33612bff2fb31f54946fb5dcadc89e905e81ec" },
2829
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
2930
"nvim-web-devicons": { "branch": "master", "commit": "8dcb311b0c92d460fac00eac706abd43d94d68af" },

lua/core/keymaps.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,22 @@ map({ "n", "v" }, "<Del>", '"_x', opts)
6969

7070

7171
map("n", "<leader>mp", "<cmd>Glow<CR>", opts)
72-
vim.keymap.set("n", "<leader>?", function()
72+
73+
map("n", "<leader>?", function()
7374
require("core.support").open()
7475
end, { noremap = true, silent = true, desc = "R NVIM: Support / Shortcuts" })
7576

77+
map("n", "<leader>sr", function()
78+
require("core.search").open_find_replace()
79+
end, { desc = "Find & Replace (Scoped)" })
80+
81+
82+
83+
map("n", "<leader>sw", function()
84+
require("spectre").open_visual({ select_word = true })
85+
end, { desc = "Replace word under cursor" })
86+
87+
map("v", "<leader>sw", function()
88+
require("spectre").open_visual()
89+
end, { desc = "Replace selection" })
90+

lua/core/lazy.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ require("lazy").setup({
8484
})
8585
end,
8686
},
87+
{
88+
"nvim-pack/nvim-spectre",
89+
dependencies = { "nvim-lua/plenary.nvim" },
90+
},
91+
8792

8893
-- LeetCode
8994
{

lua/core/search.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local M = {}
2+
3+
local function is_dashboard()
4+
return vim.bo.filetype == "rnvim_dashboard" or vim.api.nvim_buf_get_name(0) == ""
5+
end
6+
7+
function M.open_find_replace()
8+
local spectre = require("spectre")
9+
10+
if is_dashboard() then
11+
-- Dashboard → full project search
12+
spectre.open({
13+
cwd = vim.loop.cwd(),
14+
search_dirs = { vim.loop.cwd() },
15+
is_insert_mode = true,
16+
disable_devicons = false,
17+
})
18+
return
19+
end
20+
21+
local file = vim.api.nvim_buf_get_name(0)
22+
if file == "" then
23+
spectre.open()
24+
return
25+
end
26+
27+
local dir = vim.fn.fnamemodify(file, ":h")
28+
29+
spectre.open({
30+
cwd = dir,
31+
search_dirs = { dir },
32+
is_insert_mode = true,
33+
disable_devicons = false,
34+
})
35+
end
36+
37+
return M

0 commit comments

Comments
 (0)