Trigger Luasnips with hotkeys / programatically? #1235
-
I have this in my local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt
ls.add_snippets("all", {
s({trig = "````", name = "Codeblock"}, fmt([[
````{}
$TM_SELECTED_TEXT
````
]], {
i(1)
})),
s({trig = "sspan", name = "Custom Span"}, fmt("<span style=\"{}\">{}</span>", {
i(1), i(2)
})),
}) I tried this but it doesn't seem to work:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi :) vim.keymap.set({ 'n' }, "<leader>r", function () require('luasnip').snip_expand(s({trig = "````", name = "Codeblock"}, fmt([[
````{}
$TM_SELECTED_TEXT
````
]], {
i(1)
}))) end) with the required globals defined |
Beta Was this translation helpful? Give feedback.
Hi :)
snip_expand
expects a snippet, it can't handle a raw string, even if it identifies a snippet somewhat uniquely, you need to do some more stuff manually. I think #389 shows this pretty good, for an illustrating example of what's going on there trywith the required globals defined