From b286bcaa742f7bc1bdb14602f845d33868765996 Mon Sep 17 00:00:00 2001 From: Andy Teijelo Date: Fri, 9 Jun 2023 08:10:32 -0400 Subject: [PATCH] search visual selection --- lua/config/keymaps.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 63fccbb..c27ab34 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -163,6 +163,26 @@ keymap("i", "", "", opts) -- end -- -- keymap("n", "n", clean_screen, opts) + +function vim.getVisualSelection() + vim.cmd('noau normal! "vy"') + local text = vim.fn.getreg('v') + vim.fn.setreg('v', {}) + + text = string.gsub(text, "\n", "") + if #text > 0 then + return text + else + return '' + end +end + +keymap('v', 'sw', function() + local tb = require('telescope.builtin') + local text = vim.getVisualSelection() + tb.live_grep({ default_text = text }) +end, opts) + -- -- local function otherkeymaps() -- local ok