1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
local config = function()
local cmp = require("cmp")
vim.opt.completeopt = "menu,menuone"
cmp.setup({
formatting = {
expandable_indicator = false,
fields = { "abbr", "kind" },
format = require("lspkind").cmp_format({
mode = "text_symbol",
maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
before = function(_, vim_item)
vim_item.menu = ""
return vim_item
end
})
},
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = {
["<TAB>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources(
{
{ name = "nvim_lsp" },
}, {
{ name = "buffer" },
}, {
{ name = "path" },
}, {
{ name = "lazydev", group_index = 0 }
}
)
})
end
return {
"hrsh7th/nvim-cmp",
lazy = true,
event = "InsertEnter",
config = config,
dependencies = {
"neovim/nvim-lspconfig",
"onsails/lspkind.nvim",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
},
}
|