2021-09-30 17:58:22 +00:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.config_cmp()
|
|
|
|
local cmp = require("cmp")
|
2021-12-15 17:37:51 +00:00
|
|
|
cmp.setup({
|
2021-09-30 17:58:22 +00:00
|
|
|
completion = {
|
|
|
|
completeopt = "menuone,noinsert,noselect",
|
|
|
|
autocomplete = false,
|
|
|
|
},
|
2021-12-01 17:49:21 +00:00
|
|
|
expand = function(args)
|
|
|
|
require("luasnip").lsp_expand(args.body)
|
|
|
|
end,
|
2021-09-30 17:58:22 +00:00
|
|
|
sources = {
|
2021-12-15 17:37:51 +00:00
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "buffer" },
|
|
|
|
{ name = "spell" },
|
2021-08-25 23:21:50 +00:00
|
|
|
},
|
2021-12-08 23:28:12 +00:00
|
|
|
mapping = {
|
2021-12-15 17:37:51 +00:00
|
|
|
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
|
|
|
|
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
|
|
|
|
["<C-Space>"] = cmp.mapping(function()
|
2021-12-11 00:54:29 +00:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
else
|
|
|
|
cmp.complete()
|
|
|
|
end
|
2021-12-15 17:37:51 +00:00
|
|
|
end, { "i", "c" }),
|
|
|
|
["<C-e>"] = cmp.mapping({
|
|
|
|
i = cmp.mapping.abort(),
|
|
|
|
c = cmp.mapping.close(),
|
|
|
|
}),
|
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
2021-12-08 23:28:12 +00:00
|
|
|
},
|
2021-12-15 17:37:51 +00:00
|
|
|
})
|
2021-09-30 17:58:22 +00:00
|
|
|
|
|
|
|
-- Add a plug mapping to use in C-Space binding
|
|
|
|
vim.api.nvim_set_keymap(
|
|
|
|
"i",
|
|
|
|
"<Plug>(cmp_complete)",
|
|
|
|
"<cmd>lua require('cmp').complete()<CR>",
|
2021-12-15 17:37:51 +00:00
|
|
|
{ silent = true, noremap = true }
|
2021-09-30 17:58:22 +00:00
|
|
|
)
|
2021-08-25 23:21:50 +00:00
|
|
|
end
|
|
|
|
|
2021-09-30 17:58:22 +00:00
|
|
|
return M
|