Repository navigation
Expand file tree
/
Copy pathnvim-cmp.lua
More file actions
124 lines (106 loc) · 2.73 KB
/
Copy pathnvim-cmp.lua
File metadata and controls
124 lines (106 loc) · 2.73 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
-- local status, cmp = pcall(require, "cmp")
-- if not status then
-- vim.notify("没有找到 cmp")
-- return
-- end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local has_words_before = function()
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 M = {
'hrsh7th/nvim-cmp',
config = function ()
local cmp = require('cmp')
local config = {
-- 指定 snippet 引擎
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
-- 补全源
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "vsnip" },
}, {
{ name = "buffer" },
{ name = "path" },
}),
-- 快捷键设置
mapping = {
["<C-.>"] = cmp.mapping(cmp.mapping.complete(), {"i", "c"}),
["<CR>"] = cmp.mapping.confirm({
select = true,
behavior = cmp.ConfirmBehavior.Replace
}),
-- super Tab
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, {"i", "s"}),
},
-- 使用lspkind-nvim显示类型图标 (新增)
formatting = require('lsp.ui').formatting,
}
cmp.setup(config)
-- / 查找模式使用 buffer 源
cmp.setup.cmdline("/", {
sources = {
{ name = "buffer" },
},
})
-- : 命令行模式中使用 path 和 cmdline 源.
cmp.setup.cmdline(":", {
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
end,
dependencies = {
'hrsh7th/vim-vsnip',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-cmdline',
'onsails/lspkind-nvim',
'nvimdev/lspsaga.nvim'
}
}
return M
-- cmp.setup(config)
-- / 查找模式使用 buffer 源
-- cmp.setup.cmdline("/", {
-- sources = {
-- { name = "buffer" },
-- },
-- })
-- : 命令行模式中使用 path 和 cmdline 源.
-- cmp.setup.cmdline(":", {
-- sources = cmp.config.sources({
-- { name = "path" },
-- }, {
-- { name = "cmdline" },
-- }),
-- })
-- vim.g.vsnip_filetypes = {}
-- vim.g.vsnip_filetypes.javascriptreact = { 'javascript' }
-- vim.g.vsnip_snippet_dir = '~/.config/nvim/plugged/friendly-snippets/snippets'