Created
June 25, 2025 07:17
-
-
Save Kirens/265f69fb24b8fa9fd5b6ee6b2f2bfc2c to your computer and use it in GitHub Desktop.
Generalized '*' keybind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.api.nvim_set_keymap("n", "g*", function() | |
Snacks.picker.grep({ focus = "list", search = vim.fn.expand("<cword>") }) | |
end, {noremap=true, desc = "Grep keyword"}) | |
vim.api.nvim_set_keymap("v", "g*", function() | |
-- leave visual mode to update registers | |
vim.cmd 'normal! \28\14' -- :h CTRL-\_CTRL-N | |
local s = vim.fn.getpos("'<") | |
local e = vim.fn.getpos("'>") | |
local selection = vim.api.nvim_buf_get_text(0, s[2]-1, s[3]-1, e[2]-1, e[3], {}) | |
Snacks.picker.grep({ | |
focus = "list", | |
search = table.concat(selection, ' '), | |
}) | |
end, {noremap=true, desc = "Grep selection"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment