Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: search with selection text. #1175

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ _G._toggle_lazygit = function()
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
end
end

_G._buf_vtext = function()
local a_orig = vim.fn.getreg("a")
local mode = vim.fn.mode()
if mode ~= "v" and mode ~= "V" then
vim.cmd([[normal! gv]])
end
vim.cmd([[silent! normal! "aygv]])
local text = vim.fn.getreg("a")
vim.fn.setreg("a", a_orig)
return text
end
6 changes: 6 additions & 0 deletions lua/keymap/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ local plug_map = {
:with_desc("edit: Change current direrctory by zoxide"),
["n|<leader>fb"] = map_cu("Telescope buffers"):with_noremap():with_silent():with_desc("find: Buffer opened"),
["n|<leader>fs"] = map_cu("Telescope grep_string"):with_noremap():with_silent():with_desc("find: Current word"),
["v|<leader>fs"] = map_callback(function()
require("telescope.builtin").grep_string({ search = _buf_vtext() }) -- luacheck: ignore
end)
:with_noremap()
:with_silent()
:with_desc("find: Selection text"),
["n|<leader>fd"] = map_cu("Telescope persisted"):with_noremap():with_silent():with_desc("find: Session"),

-- Plugin: dap
Expand Down