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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
return {
"hrsh7th/nvim-cmp",
opts = {
sources = {
{ name = "ledger" },
{
name = "luasnip",
option = {
show_autosnippets = true,
use_show_condition = true,
},
},
{ name = "nvim_lsp", priority = 1 },
{ name = "nvim_lsp_signature_help" },
{ name = "nvim_lua" },
{ name = "path" },
{ name = "emoji" },
-- https://git.sr.ht/~amaral/nvim-cmp-fonts
{ name = "abook" },
},
formatting = {
format = {
mode = "symbol_text",
maxwidth = 50,
before = function(entry, vim_item)
return vim_item
end,
menu = {
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[LuaSnip]",
nvim_lua = "[Lua]",
latex_symbols = "[Latex]",
abook = "[Abook]",
},
},
},
},
config = function(_, opts)
local cmp = require("cmp")
local luasnip = require("luasnip")
local lspkind = require("lspkind")
cmp.setup({
sources = opts.sources,
--experimental = { ghost_text = { hl_group = "Comment" } },
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = { format = lspkind.cmp_format(opts.formatting.format) },
mapping = {
["<C-p>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<C-l>"] = cmp.mapping(function(fallback)
if luasnip.choice_active() then
luasnip.change_choice(1)
else
fallback()
end
end, { "i", "s" }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true, -- Automatically select first item on CR
}),
},
})
end,
dependencies = {
{ "L3MON4D3/LuaSnip" },
{ "hrsh7th/cmp-emoji" },
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-nvim-lsp-signature-help" },
{ "hrsh7th/cmp-nvim-lua" },
{ "hrsh7th/cmp-path" },
{ "onsails/lspkind.nvim" },
{ "saadparwaiz1/cmp_luasnip" },
{ "someone-stole-my-name/cmp-ledger" },
{
-- Not sure how stable is this, but it works for now. The first element
-- always points to $HOME/.config/nvim
dir = vim.api.nvim_list_runtime_paths()[1]
.. "/lua/plugins/dev/cmp-abook",
},
},
}
|