like in this article:
Something like that should work for templates in snipmate format.
function _G.skel(template_path)
local ls = require('luasnip')
local template = io.open(template_path, 'r')
if template == nil then
print('Template not found')
return
end
local lines = vim.split(template:read('*a'), '\n')
if lines[#lines] == '' then
table.remove(lines)
end
ls.snip_expand(ls.parser.parse_snippet('', vim.fn.join(lines, '\n')), {})
end
You can try with template file like this:
My ${1:template}!
And then:
:lua skel('/path/to/template')