forked from LazyVim/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvim-cmp.lua
More file actions
124 lines (123 loc) · 5.32 KB
/
Copy pathnvim-cmp.lua
File metadata and controls
124 lines (123 loc) · 5.32 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
-- auto completion(lvim)
-- add quarto source adnd confiugre tab complete
return {
{
"L3MON4D3/LuaSnip",
keys = function()
return {}
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip",
"jmbuhr/otter.nvim",
"hrsh7th/cmp-nvim-lsp-signature-help",
"hrsh7th/cmp-calc",
"hrsh7th/cmp-emoji",
"f3fora/cmp-spell",
"ray-x/cmp-treesitter",
"kdheepak/cmp-latex-symbols",
"jmbuhr/cmp-pandoc-references",
"L3MON4D3/LuaSnip",
"rafamadriz/friendly-snippets",
"onsails/lspkind-nvim",
"micangl/cmp-vimtex",
{ "petertriho/cmp-git", opts = {} },
},
opts = function()
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0
and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local defaults = require("cmp.config.default")()
return {
completion = {
completeopt = "menu,menuone,noinsert",
},
knippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-l>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<S-CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
-- You could replace select_next_item() with confirm({ select = true }) to get VS Code autocompletion behavior
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- this way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = 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" }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "vimtex" },
{ name = "buffer" },
{ name = "path" },
{ name = "otter" },
{ name = "nvim_lsp_signature_help" },
{ name = "calc" },
{ name = "emoji" },
{ name = "spell" },
{ name = "treesitter", keyword_length = 5, max_item_count = 3 },
{ name = "latex_symbols" },
{ name = "pandoc_references" },
{ name = "friendly_snippets" },
{ name = "lspkind_nvim" },
{ name = "git" },
}),
formatting = {
format = function(_, item)
local icons = require("lazyvim.config").icons.kinds
if icons[item.kind] then
item.kind = icons[item.kind] .. item.kind
end
return item
end,
},
experimental = {
ghost_text = {
hl_group = "CmpGhostText",
},
},
-- sorting = defaults.sorting,
}
end,
},
}