Files
dots/.config/nvim/lua/plugins/cmp.lua
2024-12-06 14:01:53 +02:00

80 lines
2.0 KiB
Lua

return {
"hrsh7th/nvim-cmp",
config = function()
require("plugins.cmp")
end,
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-nvim-lsp-signature-help",
"saadparwaiz1/cmp_luasnip",
"onsails/lspkind.nvim",
},
opts = function()
vim.opt.completeopt = { "menuone", "noselect" }
local cmp = require("cmp")
local neogen = require("neogen")
local luasnip = require("luasnip")
local lspkind = require("lspkind")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
-- ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
-- ['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
elseif neogen.jumpable() then
neogen.jump_next()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
elseif neogen.jumpable() then
neogen.jump_prev()
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = "nvim_lsp" },
{ name = "nvim_lsp_signature_help" },
{ name = "path" },
{ name = "buffer", keyword_length = 5 },
{ name = "luasnip" },
},
formatting = {
format = lspkind.cmp_format({
mode = "symbol",
maxwidth = 50,
ellipsis_char = "...",
}),
},
})
end,
}