return { 'hrsh7th/nvim-cmp', branch = 'main', lazy = false, dependencies = { 'neovim/nvim-lspconfig', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'onsails/lspkind.nvim', 'zbirenbaum/copilot-cmp', 'hrsh7th/cmp-path', 'dmitmel/cmp-cmdline-history', 'hrsh7th/cmp-nvim-lsp-signature-help', }, config = function() local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end local cmp = require('cmp') local lspkind = require('lspkind') local luasnip = require('luasnip') lspkind.init({ symbol_map = { Copilot = '', }, }) require('copilot_cmp').setup() cmp.setup({ preselect = cmp.PreselectMode.None, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) -- For `luasnip` users. end, }, mapping = { [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }), [''] = cmp.mapping({ i = function(fallback) if cmp.visible() and cmp.get_active_entry() then cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }) else fallback() end end, c = cmp.mapping.confirm({ select = false }), s = cmp.mapping.confirm({ select = false }), }), [''] = cmp.mapping(function(fallback) if luasnip.expand_or_jumpable() then vim.api.nvim_feedkeys(t('luasnip-expand-or-jump'), '', true) else fallback() end end, { 'i', 's', }), [''] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then vim.api.nvim_feedkeys(t('luasnip-jump-prev'), '', true) else fallback() end end, { 'i', 's' }), [''] = cmp.mapping( cmp.mapping.complete({ config = { sources = { { name = 'cmdline_history', }, }, }, }), { 'c' } ), }, sources = cmp.config.sources({ { name = 'copilot' }, { name = 'nvim_lsp' }, { name = 'nvim_lsp_signature_help' }, { name = 'luasnip' }, { name = 'buffer', option = { get_bufnrs = function() return vim.api.nvim_list_bufs() end, }, }, { name = 'path' }, }), window = { documentation = { winhighlight = 'Normal:CmpDocumentation', }, completion = { winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None', col_offset = -3, side_padding = 0, }, }, formatting = { fields = { 'kind', 'abbr', 'menu' }, expandable_indicator = false, format = function(entry, vim_item) local kind = require('lspkind').cmp_format({ mode = 'symbol_text', maxwidth = 50, show_labelDetails = true })(entry, vim_item) local strings = vim.split(kind.kind, '%s', { trimempty = true }) kind.kind = ' ' .. (strings[1] or '') .. ' ' kind.menu = ' (' .. (strings[2] or '') .. ')' return kind end, }, }) -- 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' }, { name = 'cmdline_history' }, { name = 'path' }, { 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 = { { name = 'cmdline', priority = 200 }, { name = 'path', priority = 3 }, { name = 'cmdline_history', priority = 3 }, { name = 'buffer', priority = 3 }, }, matching = { disallow_symbol_nonprefix_matching = false }, }) end, enabled = false }