local config = function() local cmp = require('cmp') local mapping = { [''] = { i = function() if cmp.visible() then cmp.select_next_item { behavior = cmp.SelectBehavior.Select } else cmp.complete() end end, }, [''] = { i = function() if cmp.visible() then cmp.select_prev_item { behavior = cmp.SelectBehavior.Select } else cmp.complete() end end, }, [''] = { i = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select } }, [''] = { i = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select } }, [''] = { i = cmp.mapping.scroll_docs(4) }, [''] = { i = cmp.mapping.scroll_docs(-4) }, [''] = { i = cmp.mapping.abort() }, [''] = { i = cmp.mapping.confirm { select = true } }, [''] = { i = function(fallback) if cmp.visible() then cmp.confirm { select = true } else fallback() end end, }, } cmp.setup { mapping = mapping, sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'nvim_lua' }, }, { { name = 'path' }, { name = 'buffer', keyword_length = 5 }, }), formatting = (function() local ok, lspkind = pcall(require, 'lspkind') if not ok then return {} end return { format = lspkind.cmp_format { mode = 'symbol_text', menu = { buffer = "[buf]", nvim_lsp = "[LSP]", nvim_lua = "[lua]", path = "[path]", }, }, } end)(), experimental = { ghost_text = true, }, } end return { { 'hrsh7th/nvim-cmp', config = config }, 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-path', 'hrsh7th/cmp-buffer', 'onsails/lspkind-nvim', }