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
|
||||
43
nvim/.config/nvim/lua/snippets/go.lua
Normal file
43
nvim/.config/nvim/lua/snippets/go.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
return {
|
||||
s(
|
||||
"ife",
|
||||
fmt(
|
||||
[[
|
||||
if err != nil {
|
||||
<>
|
||||
}
|
||||
]],
|
||||
{
|
||||
i(0),
|
||||
},
|
||||
{ delimiters = "<>" }
|
||||
)
|
||||
),
|
||||
|
||||
s(
|
||||
"ifse",
|
||||
fmt(
|
||||
[[
|
||||
if <><>err = <>; err != nil {
|
||||
<>
|
||||
}
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
f(function(args)
|
||||
local a = args[1][1]
|
||||
if string.sub(a, -2) == ", " or a == "" then
|
||||
return ""
|
||||
elseif string.sub(a, -1) == "," then
|
||||
return " "
|
||||
else
|
||||
return ", "
|
||||
end
|
||||
end, { 1 }),
|
||||
i(2),
|
||||
i(0),
|
||||
},
|
||||
{ delimiters = "<>" }
|
||||
)
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user