Skip to content

Instantly share code, notes, and snippets.

@Kirens
Created June 25, 2025 07:17
Show Gist options
  • Save Kirens/265f69fb24b8fa9fd5b6ee6b2f2bfc2c to your computer and use it in GitHub Desktop.
Save Kirens/265f69fb24b8fa9fd5b6ee6b2f2bfc2c to your computer and use it in GitHub Desktop.
Generalized '*' keybind
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