Skip to content

Commit 252d198

Browse files
ayamirCharlesChiuGit
authored andcommittedMar 5, 2024
feat: search with selection text. (ayamir#1175)
* feat: search with selection text. Signed-off-by: ayamir <lgt986452565@gmail.com> * chore(ci): ignore linting --------- Signed-off-by: ayamir <lgt986452565@gmail.com> Co-authored-by: CharlesChiuGit <charleschiu@hey.com>
1 parent e2105fd commit 252d198

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

‎lua/keymap/helpers.lua

+12
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ _G._toggle_lazygit = function()
3838
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
3939
end
4040
end
41+
42+
_G._buf_vtext = function()
43+
local a_orig = vim.fn.getreg("a")
44+
local mode = vim.fn.mode()
45+
if mode ~= "v" and mode ~= "V" then
46+
vim.cmd([[normal! gv]])
47+
end
48+
vim.cmd([[silent! normal! "aygv]])
49+
local text = vim.fn.getreg("a")
50+
vim.fn.setreg("a", a_orig)
51+
return text
52+
end

‎lua/keymap/tool.lua

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ local plug_map = {
132132
:with_desc("edit: Change current direrctory by zoxide"),
133133
["n|<leader>fb"] = map_cu("Telescope buffers"):with_noremap():with_silent():with_desc("find: Buffer opened"),
134134
["n|<leader>fs"] = map_cu("Telescope grep_string"):with_noremap():with_silent():with_desc("find: Current word"),
135+
["v|<leader>fs"] = map_callback(function()
136+
require("telescope.builtin").grep_string({ search = _buf_vtext() }) -- luacheck: ignore
137+
end)
138+
:with_noremap()
139+
:with_silent()
140+
:with_desc("find: Selection text"),
135141
["n|<leader>fd"] = map_cu("Telescope persisted"):with_noremap():with_silent():with_desc("find: Session"),
136142

137143
-- Plugin: dap

0 commit comments

Comments
 (0)
Please sign in to comment.