nvim-trevJ.lua icon indicating copy to clipboard operation
nvim-trevJ.lua copied to clipboard

SplitJoin.vim-like toggle functionality

Open kuator opened this issue 3 years ago • 2 comments

Is it possible to split a node under the cursor if pressed once and join if pressed again?

kuator avatar Nov 23 '22 09:11 kuator

Not at the moment but sounds like a nice feature

AckslD avatar Nov 23 '22 10:11 AckslD

This is a bit of a hack, but I got this to work:

M.join_at_cursor = function()
  local filetype = vim.bo.filetype
  if settings.containers[filetype] == nil then
    warn("filetype %s is not configured", filetype)
    return
  end
  local node = get_container_at_cursor(filetype)
  if node then
    local srow, _, erow, _ = node:range()
    vim.cmd(string.format([[%d,%djoin]], srow + 1, erow + 1))
  else
    warn "no container at cursor"
  end
end

luan avatar Jan 28 '23 01:01 luan