dotfiles/vim/lua/nvim_cmp_config.lua

79 lines
1.9 KiB
Lua
Raw Normal View History

2023-09-19 05:21:43 +00:00
local cmp = require("cmp")
2023-09-21 14:00:41 +00:00
-- local cmp_buffer = require("cmp_buffer")
cmp.setup({
2023-09-19 05:21:43 +00:00
completion = {
2023-09-22 12:26:13 +00:00
completeopt = "menu,menuone,noselect",
2023-09-19 05:21:43 +00:00
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
2023-09-21 14:00:41 +00:00
preselect = cmp.PreselectMode.None,
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
2023-09-19 05:21:43 +00:00
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 }),
2023-09-22 12:26:13 +00:00
-- 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,
2023-09-19 05:21:43 +00:00
}),
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 = {
2023-09-21 14:00:41 +00:00
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,
2023-09-19 05:21:43 +00:00
},
},
2023-09-21 14:00:41 +00:00
formatting = {
fields = { "kind", "abbr", "menu" },
2023-09-19 05:21:43 +00:00
},
experimental = {
ghost_text = true,
},
})