vim.api.nvim_create_autocmd("PackChanged", { group = vim.api.nvim_create_augroup("luasnip-update", { clear = true }), callback = function(ev) local name, kind = ev.data.spec.name, ev.data.kind if name == "luasnip" and (kind == "install" or kind == "update") then vim.system({ "make install_jsregexp" }, { cwd = ev.data.path }):wait() print("luasnip make done.") end end, }) vim.pack.add({ { src = "https://github.com/L3MON4D3/LuaSnip", version = vim.version.range("^2.0.0") } }) local ok, ls = pcall(require, "luasnip") if ok then vim.keymap.set({ "i" }, "", function() ls.expand() end, { silent = true }) vim.keymap.set({ "i", "s" }, "", function(fallback) if ls.locally_jumpable() then ls.jump(1) else local key = vim.api.nvim_replace_termcodes("", true, false, true) vim.api.nvim_feedkeys(key, "n", false) end end, { silent = true }) vim.keymap.set({ "i", "s" }, "", function() if ls.locally_jumpable() then ls.jump(-1) else local key = vim.api.nvim_replace_termcodes("", true, false, true) vim.api.nvim_feedkeys(key, "n", false) end end, { silent = true }) vim.keymap.set({ "i", "s" }, "", function() if ls.choice_active() then ls.change_choice(1) else local key = vim.api.nvim_replace_termcodes("", true, false, true) vim.api.nvim_feedkeys(key, "n", false) end end, { silent = true }) require("luasnip.loaders.from_lua").load({ paths = vim.fs.joinpath(vim.fn.stdpath("config"), "lua", "snippets") }) else print("plugin luasnip missing") end