return { 'hrsh7th/nvim-cmp', event = { 'InsertEnter', 'CmdlineEnter' }, dependencies = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', 'petertriho/cmp-git', 'onsails/lspkind-nvim', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', }, config = function() local cmp = require('cmp') local lspkind = require('lspkind') -- NO luasnip require here cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) -- lazy, only on snippet expand end, }, 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.confirm({ select = false }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() else local luasnip = require('luasnip') -- lazy, only on keypress if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() else local luasnip = require('luasnip') -- lazy, only on keypress if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end end, { 'i', 's' }), }), sources = { { name = 'nvim_lsp', priority = 1000 }, { name = 'luasnip', priority = 900 }, { name = 'path', priority = 750 }, { name = 'buffer', priority = 500, keyword_length = 5, max_item_count = 50, option = { get_bufnrs = function() return { vim.api.nvim_get_current_buf() } -- only index current buffer, not all open buffers end, }, }, }, formatting = { fields = { 'abbr', 'kind', 'menu' }, expandable_indicator = false, format = lspkind.cmp_format({ mode = 'symbol_text', maxwidth = 50, ellipsis_char = '...', menu = { nvim_lsp = '[LSP]', luasnip = '[Snip]', buffer = '[Buffer]', path = '[Path]', }, }), }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, performance = { confirm_resolve_timeout = 100, max_view_entries = 20, debounce = 60, throttle = 30, fetching_timeout = 200, }, }) cmp.setup.filetype('gitcommit', { -- only once sources = { { name = 'git', priority = 900 }, { name = 'buffer', keyword_length = 5 }, }, }) local cmdline_mapping = cmp.mapping.preset.cmdline({ [''] = { c = cmp.mapping.select_next_item() }, [''] = { c = cmp.mapping.select_prev_item() }, [''] = { c = cmp.mapping.select_next_item() }, [''] = { c = cmp.mapping.select_prev_item() }, }) cmp.setup.cmdline({ '/', '?' }, { mapping = cmdline_mapping, sources = { { name = 'buffer', keyword_length = 5 } }, }) cmp.setup.cmdline(':', { mapping = cmdline_mapping, sources = { { name = 'path' }, { name = 'cmdline' }, }, window = { documentation = cmp.config.window.bordered({ winhighlight = 'Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None', border = 'rounded', }), }, }) end, }