Skip to content

Commit 122c017

Browse files
committed
feat(normal): search first occurrence of word
1 parent f7fe72f commit 122c017

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

lazy-lock.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"mini.pairs": { "branch": "main", "commit": "1e1ca3f60f58d4050bf814902b472eec9963a5dd" },
2121
"mini.surround": { "branch": "main", "commit": "b12fcfefd6b9b7c9e9a773bc0e3e07ae20c03351" },
2222
"nvim-dap": { "branch": "master", "commit": "5dd4d50f2e6a2eaf9e57fad023d294ef371bda35" },
23-
"nvim-dap-view": { "branch": "main", "commit": "c7385808c7d6a4438f6eef50d539d7103146ba2b" },
23+
"nvim-dap-view": { "branch": "main", "commit": "143411d3e5d76814345030d7029af935afc7116d" },
2424
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
2525
"nvim-treesitter-refactor": { "branch": "master", "commit": "d8b74fa87afc6a1e97b18da23e762efb032dc270" },
26-
"nvim-treesitter-textobjects": { "branch": "master", "commit": "89ebe73cd2836db80a22d9748999ace0241917a5" },
26+
"nvim-treesitter-textobjects": { "branch": "master", "commit": "71385f191ec06ffc60e80e6b0c9a9d5daed4824c" },
2727
"nvim-ts-autotag": { "branch": "main", "commit": "a1d526af391f6aebb25a8795cbc05351ed3620b5" },
2828
"nvim-web-devicons": { "branch": "master", "commit": "4a8369f4c78ef6f6f895f0cec349e48f74330574" },
2929
"oil.nvim": { "branch": "master", "commit": "bbad9a76b2617ce1221d49619e4e4b659b3c61fc" },

plugin/keymaps/normal.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,23 @@ for key, desc in pairs(mark_search_keys) do
9090
k(key, "ms" .. key, { desc = desc })
9191
end
9292

93+
-- Search for first occurrence of word under cursor
94+
k("[i", "ms[<c-i>", { desc = "Search for first occurrence of word under cursor" }) -- `:h [_ctrl-i`
95+
96+
-- Search for first occurrence of word under cursor, in a new window
97+
k("<c-w>i", function()
98+
local word = vim.fn.expand("<cword>")
99+
if word ~= "" then
100+
vim.cmd("only | vsplit | silent! ijump /" .. word .. "/") -- `:h ijump`
101+
end
102+
end, { desc = "Search for first occurrence of word under cursor in new window" })
103+
93104
-- Clear search highlight when moving back to position before starting the search
94105
k("'s", function()
95106
vim.cmd("normal! `s")
96107
vim.cmd.nohlsearch()
97108
end, { desc = "Jump to where search started" })
98109

99-
-- Search current word from the beginning of the file `:h [i`
100-
-- Jump back to where the search started with `'s`
101-
k("<c-8>", function()
102-
local cword = vim.fn.expand("<cword>")
103-
if cword ~= "" then
104-
vim.fn.setreg("/", "\\<" .. vim.fn.escape(cword, [[\/.*$^~[]()]]) .. "\\>")
105-
vim.cmd("keepjumps normal! gg0nzv")
106-
end
107-
end, { desc = "Jump to first occurrence" })
108-
109110
-- }}}
110111

111112
-- Buffers {{{

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ Random features added.
200200
- `<leader>/` find in workspace
201201
- `<leader>?` find in directory
202202
- `g/` search in selection
203+
- `[i` search first occurrence
204+
- `<c-w>i` search first occurence in new window
203205
- `<c-8>` find current word from the beginning of the file
204206
- `'s` jump back to where search started
205207

0 commit comments

Comments
 (0)