From 23de12baba9fbfc4ca24581b37c374aa5345cc25 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Mon, 25 Nov 2024 13:30:37 +0100 Subject: update nvim config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .vim/after/ftplugin/html.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .vim/after/ftplugin/html.lua (limited to '.vim/after/ftplugin/html.lua') diff --git a/.vim/after/ftplugin/html.lua b/.vim/after/ftplugin/html.lua new file mode 100644 index 0000000..35f0bd1 --- /dev/null +++ b/.vim/after/ftplugin/html.lua @@ -0,0 +1,20 @@ +local function get_visual_selection() + local start_pos = vim.fn.getpos('v') + local end_pos = vim.fn.getpos('.') + local text = vim.fn.getregion(vim.fn.getpos('v'), vim.fn.getpos('.'), { type = vim.fn.mode() }) + return { start_pos = start_pos, end_pos = end_pos, text = text } +end + +vim.keymap.set('x', '', function() + local sel = get_visual_selection() + vim.print(sel) + vim.api.nvim_buf_set_text( + sel.start_pos[1], -- bufnum + sel.start_pos[2] - 1, -- vim.api funcs use 0-based indexing + sel.start_pos[3] - 1, + sel.end_pos[2] - 1, + sel.end_pos[3], + { '' .. table.concat(sel.text, '') .. '' } + ) + vim.api.nvim_input('') +end, { desc = 'html: make link' }) -- cgit 1.4.1