nixos-config/home/nvim/lua/config/nvim-cmp.lua

54 lines
1.2 KiB
Lua

local cmp = require("cmp")
local luasnip = require("luasnip");
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
["<C-h"] = cmp.mapping.abort(),
["<C-k>"] = cmp.mapping(function(fallback)
if cmp.visible() then
if luasnip.expandable() then
luasnip.expand()
else
cmp.confirm({
select = true,
})
end
else
fallback()
end
end),
["<C-n>"] = cmp.mapping(function(fallback)
if luasnip.locally_jumpable(1) then
luasnip.jump(1)
elseif cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { "i", "s" }),
["<C-p>"] = cmp.mapping(function(fallback)
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
elseif cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources ({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "buffer" },
{ name = "path" },
})
}