You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB
Lua

1 week ago
local M = { 'hrsh7th/nvim-cmp' }
M.name = 'cmp'
M.dependencies = {
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lsp',
}
function M.config()
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local function expand(args)
luasnip.lsp_expand(args.body)
end
local function tab_mapping(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end
local function back_tab_mapping(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end
cmp.setup {
enabled = true,
snippet = { expand = expand },
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
mapping = cmp.mapping.preset.insert {
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete({}),
['<Tab>'] = cmp.mapping(tab_mapping, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(back_tab_mapping, { 'i', 's' }),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
},
}
end
1 week ago
return M