-
For Lua I'm making a simple
So that expanding with (
Would insert
Would insert I tried to use inject the termcodes for moving the cursor but that doesn't work / inserts garbage: s({trig = "r", desc = "return ..."}, {
ls.function_node(function()
local line = vim.api.nvim_get_current_line()
local col = vim.fn.col(".")
local char = line:sub(col, col)
if char == " " then
local move_right = vim.api.nvim_replace_termcodes("<C-g>U<Right>", true, false, true)
return "return" .. move_right
else
return "return "
end
end)
}) And I couldn't find a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Oh, I think I have a nice way of achieving this: instead of moving the cursor after expansion, include any whitespace behind the cursor in the trigger! Moving the cursor reliably is more complicated I think, luasnip has a kind of queue for all movement-commands and I'd have to expose some way to enqueue into it (and add a callback that is invoked at the right time :D) |
Beta Was this translation helpful? Give feedback.
Oh, I think I have a nice way of achieving this: instead of moving the cursor after expansion, include any whitespace behind the cursor in the trigger!
While this is not possible with the trigger using the
"plain"
trigEngine
, you can useresolveExpandParams
to manipulate the region that is treated as the trigger (ie. deleted before expansion).Moving the cursor reliably is more complicated I think, luasnip has a kind of queue for all movement-commands and I'd have to expose some way to enqueue into it (and add a callback that is invoked at the right time :D)