2023-07-10 22:33:59 +02:00
|
|
|
-- Reference: https://github.com/hrsh7th/nvim-cmp#recommended-configuration
|
2024-01-23 22:23:58 +01:00
|
|
|
return function()
|
2023-07-10 22:33:59 +02:00
|
|
|
local cmp = require "cmp"
|
|
|
|
|
2024-05-20 18:55:58 +02:00
|
|
|
cmp.setup {
|
2023-07-10 22:33:59 +02:00
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
2024-05-20 18:55:58 +02:00
|
|
|
vim.snippet.expand(args.body)
|
2023-07-10 22:33:59 +02:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
window = {
|
|
|
|
completion = cmp.config.window.bordered(),
|
|
|
|
documentation = cmp.config.window.bordered(),
|
|
|
|
},
|
2024-05-20 18:55:58 +02:00
|
|
|
mapping = cmp.mapping.preset.insert {
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif vim.snippet.jumpable(1) then
|
|
|
|
vim.snippet.jump(1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
-- And something similar for vim.snippet.jump(-1)
|
|
|
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
2023-07-10 22:33:59 +02:00
|
|
|
['<C-CR>'] = cmp.mapping.complete(),
|
2024-05-20 18:55:58 +02:00
|
|
|
['<C-e>'] = cmp.mapping.abort(),
|
|
|
|
['<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 = 'buffer' }})
|
|
|
|
}
|
2023-07-10 22:33:59 +02:00
|
|
|
|
|
|
|
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
|
|
|
cmp.setup.cmdline({ '/', '?' }, {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = {
|
|
|
|
{ name = 'buffer' }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
|
|
|
cmp.setup.cmdline(':', {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'path' }
|
|
|
|
}, {
|
|
|
|
{ name = 'cmdline' }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
end
|