From 83ae474da5d424b0f060cabadf49e273e1b42c1f Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sun, 19 May 2024 01:04:13 +0200 Subject: nvim: wip: add highlight --- nvim/nvim/lua/highlight.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nvim/nvim/lua/highlight.lua diff --git a/nvim/nvim/lua/highlight.lua b/nvim/nvim/lua/highlight.lua new file mode 100644 index 0000000..2fe26e0 --- /dev/null +++ b/nvim/nvim/lua/highlight.lua @@ -0,0 +1,34 @@ +local ns = vim.api.nvim_create_namespace("highlight") + +-- Highlight when yanking (copying) text +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) + +-- TODO: +-- https://medium.com/@ankochem/neovim-highlighting-the-text-programmatically-with-lua-837fecfa36d2 +-- Highlight whatever the user selected +-- function highlight_selection() +-- local start = vim.api.nvim_buf_get_mark(0, '[') +-- local finish = vim.api.nvim_buf_get_mark(0, ']') +-- start[1] = start[1] - 1 +-- if start[1] < 0 then start[1] = 0 end +-- start[2] = start[2] + 1 +-- finish[1] = finish[1] - 1 +-- if finish[1] < 0 then finish[1] = 0 end +-- finish[2] = finish[2] + 1 +-- vim.highlight.range(0, ns, "IncSearch", start, finish) +-- end +-- +-- function clean_highlight() +-- vim.api.nvim_buf_clear_namespace(0, ns, 0, -1) +-- vim.cmd("redraw") +-- end +-- +-- -- TODO +-- vim.keymap.set('n', '', highlight_selection) +-- vim.keymap.set('n', '', clean_highlight) -- cgit v1.2.3