nvim: add luasnip
This commit is contained in:
48
nvim/.config/nvim/lua/plugins/luasnip.lua
Normal file
48
nvim/.config/nvim/lua/plugins/luasnip.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
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" }, "<C-K>", function()
|
||||
ls.expand()
|
||||
end, { silent = true })
|
||||
vim.keymap.set({ "i", "s" }, "<C-L>", function(fallback)
|
||||
if ls.locally_jumpable() then
|
||||
ls.jump(1)
|
||||
else
|
||||
local key = vim.api.nvim_replace_termcodes("<C-L>", true, false, true)
|
||||
vim.api.nvim_feedkeys(key, "n", false)
|
||||
end
|
||||
end, { silent = true })
|
||||
vim.keymap.set({ "i", "s" }, "<C-J>", function()
|
||||
if ls.locally_jumpable() then
|
||||
ls.jump(-1)
|
||||
else
|
||||
local key = vim.api.nvim_replace_termcodes("<C-J>", true, false, true)
|
||||
vim.api.nvim_feedkeys(key, "n", false)
|
||||
end
|
||||
end, { silent = true })
|
||||
|
||||
vim.keymap.set({ "i", "s" }, "<C-E>", function()
|
||||
if ls.choice_active() then
|
||||
ls.change_choice(1)
|
||||
else
|
||||
local key = vim.api.nvim_replace_termcodes("<C-E>", 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
|
||||
Reference in New Issue
Block a user