new visual selection highlight

This commit is contained in:
Oliver Hartmann
2025-12-15 07:24:03 +00:00
parent fd6d0019f1
commit c201b75596

View File

@@ -46,8 +46,25 @@ end
-- Highlight word under cursor -- Highlight word under cursor
vim.keymap.set('n', "'", hlWord, { noremap = true, silent = true, desc = 'Higlight word under cursor' }) vim.keymap.set('n', "'", hlWord, { noremap = true, silent = true, desc = 'Higlight word under cursor' })
vim.keymap.set('x', "'", 'y/\\V<C-R>"<CR>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 -- Close Buffer
-- vim.keymap.set('n', '<C-w>', ':bd<CR>', { desc = 'Close buffer' }) -- vim.keymap.set('n', '<C-w>', ':bd<CR>', { desc = 'Close buffer' })