50 lines
1.2 KiB
Lua
50 lines
1.2 KiB
Lua
local map = core.misc.map
|
|
|
|
return { "L3MON4D3/LuaSnip",
|
|
branch = "v2.*",
|
|
config = function()
|
|
vim.cmd("make install_jsregexp")
|
|
end,
|
|
lazy = function(load)
|
|
load:keymap({"i", "s"}, "<c-a>")
|
|
load:keymap({"i", "s"}, "<c-e>")
|
|
load:keymap({"i", "s"}, "<c-j>")
|
|
load:keymap({"i", "s"}, "<c-k>")
|
|
load:auto("InsertEnter")
|
|
end,
|
|
load = function()
|
|
local ls = require("luasnip")
|
|
|
|
-- replace the builtin snippet handler with luasnip so I get all my fancy
|
|
-- stuff
|
|
vim.snippet.expand = ls.lsp_expand
|
|
|
|
ls.config.setup {
|
|
keep_roots = true,
|
|
link_roots = true,
|
|
link_children = true,
|
|
exit_roots = not true
|
|
}
|
|
|
|
map({"i", "s"}, "<C-e>", ls.expand)
|
|
map({"i", "s"}, "<C-j>", function() ls.jump(1) end)
|
|
map({"i", "s"}, "<C-k>", function() ls.jump(-1) end)
|
|
map({"i", "s"}, "<C-a>", function()
|
|
if ls.choice_active() then
|
|
ls.change_choice(1)
|
|
end
|
|
end)
|
|
|
|
-- collect all snippets and add them
|
|
for _, file in ipairs(vim.api.nvim_get_runtime_file("lua/snippets/*.lua",
|
|
true)) do
|
|
local fn = file:gsub("^.*/", ""):gsub("%.lua$", "")
|
|
|
|
local ret = require("snippets."..fn)
|
|
if type(ret) ~= "boolean" then
|
|
ls.add_snippets(fn, ret, { key = fn })
|
|
end
|
|
end
|
|
end
|
|
}
|