2023-06-09 00:05:07 +08:00
|
|
|
local cmp = require('cmp')
|
|
|
|
|
2023-06-09 00:43:36 +08:00
|
|
|
local copt = vim.fn['SpaceVim#layers#autocomplete#get_variable']()
|
|
|
|
|
|
|
|
|
|
|
|
-- 1. `auto_completion_return_key_behavior` set the action to perform
|
|
|
|
-- when the `Return`/`Enter` key is pressed. the possible values are:
|
|
|
|
-- - `complete` completes with the current selection
|
|
|
|
-- - `smart` completes with current selection and expand snippet or argvs
|
|
|
|
-- - `nil`
|
|
|
|
-- By default it is `complete`.
|
|
|
|
|
2023-06-09 00:21:40 +08:00
|
|
|
local feedkey = function(key, mode)
|
|
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
|
|
|
end
|
|
|
|
|
2023-06-09 00:05:07 +08:00
|
|
|
cmp.setup({
|
|
|
|
mapping = {
|
|
|
|
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
|
|
|
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
|
|
|
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
|
|
|
['<C-e>'] = cmp.mapping({
|
|
|
|
i = cmp.mapping.abort(),
|
|
|
|
c = cmp.mapping.close(),
|
|
|
|
}),
|
|
|
|
['<Tab>'] = function(fallback)
|
2023-06-09 00:43:36 +08:00
|
|
|
if copt.auto_completion_return_key_behavior == 'smart'
|
|
|
|
and vim.fn['neosnippet#expandable_or_jumpable']() == 1
|
|
|
|
then
|
2023-06-09 00:21:40 +08:00
|
|
|
feedkey('<plug>(neosnippet_expand_or_jump)', '')
|
2023-06-09 00:43:36 +08:00
|
|
|
elseif cmp.visible() and copt.auto_completion_return_key_behavior == 'complete' then
|
2023-06-09 00:05:07 +08:00
|
|
|
cmp.select_next_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
['<S-Tab>'] = function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
|
|
},
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'path' },
|
|
|
|
{ name = 'neosnippet' },
|
|
|
|
}, {
|
|
|
|
{ name = 'buffer' },
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Setup lspconfig.
|
|
|
|
local capabilities =
|
|
|
|
require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
|
|
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
|