dotfiles/vim/lua/nvim_cmp_config.lua

79 lines
1.9 KiB
Lua

local cmp = require("cmp")
-- local cmp_buffer = require("cmp_buffer")
cmp.setup({
completion = {
completeopt = "menu,menuone,noselect",
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
preselect = cmp.PreselectMode.None,
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
["C-y"] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }),
["<CR>"] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }),
-- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#super-tab-like-mapping
["<C-Space>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
["<Tab>"] = function(fallback)
if not cmp.select_next_item() then
if vim.bo.buftype ~= "prompt" and has_words_before() then
cmp.complete()
else
fallback()
end
end
end,
["<S-Tab>"] = function(fallback)
if not cmp.select_prev_item() then
if vim.bo.buftype ~= "prompt" and has_words_before() then
cmp.complete()
else
fallback()
end
end
end,
}),
sources = cmp.config.sources({
{ name = "copilot", keyword_length = 0 },
{ name = "nvim_lsp", keyword_length = 3 },
{
name = "buffer",
option = {
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end,
},
},
{ name = "path" },
{ name = "calc" },
}),
sorting = {
comparators = {
cmp.config.compare.offset,
cmp.config.compare.exact,
cmp.config.compare.score,
cmp.config.compare.recently_used,
-- require("cmp-under-comparator").under,
cmp.config.compare.kind,
},
},
formatting = {
fields = { "kind", "abbr", "menu" },
},
experimental = {
ghost_text = true,
},
})