fix(nvim): Finally get custom snippets working

This commit is contained in:
punkfairie 2024-02-23 20:29:55 -08:00
parent f674f47ff6
commit ce9ae3617f
2 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,10 @@
return {
{
"L3MON4D3/LuaSnip",
config = function(_, opts)
require("luasnip").setup(opts)
require("luasnip.loaders.from_lua").lazy_load({ lazy_paths = { "~/.config/nvim/lua/snippets" } })
end,
},
}

View file

@ -0,0 +1,100 @@
local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt
return {
s({ trig = "#!", desc = "shebang" }, t("#!/usr/bin/env fish")),
s(
{ trig = "if", desc = "if ... end" },
fmt(
[[
if {}
{}
end
]],
{ i(1), i(0) }
)
),
s(
{ trig = "elif", desc = "else if ..." },
fmt(
[[
else if {}
{}
]],
{ i(1), i(0) }
)
),
s(
{ trig = "fori", desc = "for ... in ... end" },
fmt(
[[
for {} in {}
{}
end
]],
{ i(1), i(2), i(0) }
)
),
s(
{ trig = "wh", desc = "while ... end" },
fmt(
[[
while {}
{}
end
]],
{ i(1), i(0) }
)
),
s(
{ trig = "wht", desc = "while true ... end" },
fmt(
[[
while true
{}
end
]],
{ i(0) }
)
),
s(
{ trig = "sw", desc = "switch ... case ... end" },
fmt(
[[
switch {}
case {}
{}
end
]],
{ i(1), i(2), i(0) }
)
),
s(
{ trig = "func", desc = "function ... end" },
fmt(
[[
function {}
{}
end
]],
{ i(1), i(0) }
)
),
s({ trig = "dn", desc = "&>/dev/null" }, t("&>/dev/null")),
s(
{ trig = "abbr", desc = "abbr -a ... --position ..." },
fmt('abbr -a {} --position {} "{}"', { i(1), i(2, "command"), i(3) })
),
}