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 { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete({}), [''] = cmp.mapping(tab_mapping, { 'i', 's' }), [''] = cmp.mapping(back_tab_mapping, { 'i', 's' }), [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, }, } end return M