Automatically apply skeleton snippets to certain filetypes if configured

This commit is contained in:
2025-08-26 03:39:00 +02:00
parent 0dc1eeaaf5
commit 6491093ae3
4 changed files with 54 additions and 3 deletions

View File

@@ -1,3 +1,30 @@
-- idea stolen from: https://vi.stackexchange.com/a/42370
local skelconfig = vim.api.nvim_create_augroup('SKEL_CONFIG', { clear = true })
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
group = skelconfig,
callback = function()
-- another autocmd so it doesn't conflict
-- with other plugins that like to insert text on file open
vim.api.nvim_create_autocmd("VimEnter", {
group = skelconfig,
callback = function()
-- stop if buffer is not empty!
if vim.fn.line("$") ~= 1 or vim.fn.getline(1) ~= "" then
return
end
local ls = require('luasnip')
local snippets = ls.get_snippets(vim.bo.ft)
for _, snippet in ipairs(snippets) do
if snippet["name"] == "_skeleton" then
ls.snip_expand(snippet)
return true
end
end
end
})
end,
})
return {
"L3MON4D3/LuaSnip",
version = "v2.*", -- just because the docs mention it