diff --git a/lua/my_keymappings.lua b/lua/my_keymappings.lua index e89a443..fcfb498 100644 --- a/lua/my_keymappings.lua +++ b/lua/my_keymappings.lua @@ -46,8 +46,25 @@ end -- Highlight word under cursor vim.keymap.set('n', "'", hlWord, { noremap = true, silent = true, desc = 'Higlight word under cursor' }) -vim.keymap.set('x', "'", 'y/\\V"N', { noremap = true, silent = true, desc = 'Highlight visual' }) +vim.keymap.set('x', "'", function() + -- 1. Yank current visual selection into the 'v' register + vim.cmd('noau normal! "vy"') + local text = vim.fn.getreg('v') + -- 2. Escape special characters (\ and /) for search + text = vim.fn.escape(text, '\\/') + + -- 3. Replace actual newlines with the string "\n" + text = string.gsub(text, '\n', '\\n') + + -- 4. Set the search register with \V (very nomagic) for literal search + vim.fn.setreg('/', '\\V' .. text) + + -- 5. Turn on highlight search + vim.opt.hlsearch = true + + -- Optional: Print feedback +end, { desc = 'Search for selected text (multiline supported)' }) -- Close Buffer -- vim.keymap.set('n', '', ':bd', { desc = 'Close buffer' })