summary refs log tree commit diff
path: root/.vim/after/ftplugin/html.lua
blob: 35f0bd1a65293f2a3076b5015e3a72b2088deb63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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' })