1
0

add snippets for common languages

This commit is contained in:
2025-04-02 20:01:11 +02:00
parent d4e4eaefa3
commit 7d3ef607c2
6 changed files with 865 additions and 9 deletions

View File

@@ -9,15 +9,24 @@ return {
build = "make install_jsregexp",
config = function()
local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
ls.add_snippets("lua", {
s("hello", {
t('print("hello world!")'),
}),
})
local snippets_folder = vim.fn.stdpath("config") .. "/snippets"
local function load_snippets()
-- Load all Lua files in the snippets directory except init.lua
local files = vim.fn.glob(snippets_folder .. "/*.lua", false, true)
for _, file in ipairs(files) do
local filename = vim.fn.fnamemodify(file, ":t")
-- Remove .lua extension to get the filetype
local ft = filename:match("(.+)%.lua$")
if ft then
-- Load the file which should return a table of snippets
local ok, snippets = pcall(dofile, file)
if ok and type(snippets) == "table" then
ls.add_snippets(ft, snippets)
end
end
end
end
load_snippets()
end,
},
{