1
0

add lua snippet

This commit is contained in:
Rokas Puzonas 2023-05-11 17:30:35 +03:00
parent 9efae9f0f4
commit 2fe153a57a

View File

@ -2,10 +2,11 @@ local ls = require("luasnip")
local capture = require("utils.capture") local capture = require("utils.capture")
local s = ls.snippet local s = ls.snippet
local sn = ls.snippet_node local sn = ls.snippet_node
local fmt = require("luasnip.extras.fmt").fmt
local t = ls.text_node local t = ls.text_node
local i = ls.insert_node local i = ls.insert_node
local f = ls.function_node local f = ls.function_node
local choice = ls.choice_node local c = ls.choice_node
local d = ls.dynamic_node local d = ls.dynamic_node
local function getCurrentYear() local function getCurrentYear()
@ -20,6 +21,18 @@ local function getGitUsername()
return stdout return stdout
end end
ls.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI",
enable_autosnippets = true
}
vim.keymap.set({"i"}, "<c-l>", function()
if ls.choice_active() then
ls.change_choice(1)
end
end)
ls.add_snippets("all", { ls.add_snippets("all", {
s("MIT", { s("MIT", {
t({"The MIT License (MIT)", "Copyright © "}), t({"The MIT License (MIT)", "Copyright © "}),
@ -53,3 +66,15 @@ ls.add_snippets("all", {
} }
}) })
}) })
ls.add_snippets("lua", {
s("req",
fmt([[local {} = require("{}")]], {
f(function(module_name)
local parts = vim.split(module_name[1][1], ".", true)
return (parts[#parts] or ""):gsub("-", "_")
end, { 1 }),
i(1)
})
)
})