summary refs log tree commit diff
path: root/.vim/after/ftplugin/html.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2024-11-25 13:30:37 +0100
committerRobert Günzler <r@gnzler.io>2024-11-25 13:58:25 +0100
commit23de12baba9fbfc4ca24581b37c374aa5345cc25 (patch)
treee4b3c421bad572eb85a1089eaad44dc3059ab6e6 /.vim/after/ftplugin/html.lua
parent18e3848110da0a59843058927ea04b496f5db2a5 (diff)
update nvim config
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/after/ftplugin/html.lua')
-rw-r--r--.vim/after/ftplugin/html.lua20
1 files changed, 20 insertions, 0 deletions
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', '<c-l>', 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],
+    { '<a href="TODO">' .. table.concat(sel.text, '') .. '</a>' }
+  )
+  vim.api.nvim_input('<esc>')
+end, { desc = 'html: make link' })