return { 'hrsh7th/cmp-buffer', -- nvim-cmp source for buffer words 'hrsh7th/cmp-path', -- completion pathname 'hrsh7th/cmp-nvim-lsp', -- nvim-cmp source for neovim's built-in LSP { 'hrsh7th/nvim-cmp', -- Completion config = function() local cmp = require 'cmp' local lspkind = require 'lspkind' local luasnip = require 'luasnip' local has_words_before = function() if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then return false end local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_text(0, line-1, 0, line-1, col, {})[1]:match("^%s*$") == nil end cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = vim.schedule_wrap(function(fallback) if cmp.visible() and has_words_before() then cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s" }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'buffer', option = { get_bufnrs = function () return vim.api.nvim_list_bufs() end } }, { name = 'path' }, { name = 'luasnip' } }), formatting = { format = lspkind.cmp_format({ with_text = false, maxwidth = 50 }) } }) vim.cmd [[ set completeopt=menuone,noinsert,noselect highlight! default link CmpItemKind CmpItemMenuDefault ]] end, }, }