snippets: load my own snippets

- Renames the snippets folder to my_snippets.
- Loads my snippets.
- Creates two snippet example available for all filetypes.
- Creates three snippets for markdown filetype.

Co-Authored-by: iGor milhit <igor.milhit@unige.ch>
iGor milhit 2023-06-09 13:00:41 +02:00
parent 402e5a9308
commit 8d6a060eca
Signed by: igor
GPG Key ID: 692D97C3D0228A99
5 changed files with 74 additions and 1 deletions

View File

@ -519,9 +519,12 @@ luasnip.config.setup {
snippets = {
markdown = {},
},
luasnip.filetype_extend("pandoc", {"markdown"})
luasnip.filetype_extend("pandoc", {"markdown"}),
}
-- Load snippets from ~/.config/nvim/LuaSnip/
require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"})
cmp.setup {
snippet = {
expand = function(args)

View File

@ -0,0 +1,14 @@
return {
-- A snippet that expands the trigger "hi" into the string "Hello, world!".
require("luasnip").snippet(
{ trig = "hi" },
{ t("Hello, world!") }
),
-- To return multiple snippets, use one `return` statement per snippet file
-- and return a table of Lua snippets.
require("luasnip").snippet(
{ trig = "foo" },
{ t("Another snippet.") }
)
}

View File

@ -0,0 +1,56 @@
local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
-- Function to get the datetime
-- with daylight saving time
-- according to the locale
local get_date = function()
return os.date("%Y-%m-%dT%H:%M:%S%z")
end
-- Function to get an id based on the datetime
local get_id = function()
return os.date("%Y%m%d%H%M%S")
end
return {
s(
{
trig = "datetime",
dscr = "Insert datetime with locale daylight saving"
},
{
f(get_date, {})
}
),
s(
{
trig = "id",
dscr = "Insert an id based on the datetime"
},
{
f(get_id, {})
}
),
s(
{
trig = "yaml",
dscr = "Insert a YAML frontmatter for markdown"
},
{
t { "---", "title: " },
i(1, "title"),
t{ "", "date: " },
f(get_date, {}),
t{ "", "id: " },
f(get_id, {}),
t{ "","tags: [" },
i(2, "tags"),
t{ "]", "---", "" },
i(0),
}
)
}