return { "hrsh7th/nvim-cmp", event = "VimEnter", dependencies = { "hrsh7th/cmp-buffer", -- source for text in buffer "hrsh7th/cmp-path", -- source for file system paths "hrsh7th/cmp-nvim-lsp-document-symbol", "hrsh7th/cmp-nvim-lsp-signature-help", { "hrsh7th/vim-vsnip", config = function() vim.g.vsnip_snippet_dir = "$XDG_CONFIG_HOME/nvim/snippets" vim.cmd [[ autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item) autocmd BufWritePre lua vim.lsp.buf.format({}, 10000) ]] end, }, "hrsh7th/cmp-vsnip", "onsails/lspkind.nvim", -- vs-code like pictogram "hrsh7th/cmp-cmdline", }, config = function() local cmp = require("cmp") local lspkind = require("lspkind") local has_words_before = function() unpack = unpack or table.unpack local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end cmp.setup({ window = { completion = cmp.config.window.bordered({ border = 'double', winhighlight = "Normal:CmpNormal", }), documentation = cmp.config.window.bordered({ border = 'double', winhighlight = "Normal:CmpDocNormal", }), }, snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.confirm { select = true }, [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("(vsnip-expand-or-jump)", "") elseif has_words_before() then cmp.complete() else fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. end end, { "i", "s" }), [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("(vsnip-jump-prev)", "") end end, { "i", "s" }), }), experimental = { ghost_text = true, }, sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = 'vsnip' }, { name = "buffer" }, { name = "path" }, }), }) -- `/` cmdline setup. cmp.setup.cmdline('/', { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) -- `:` cmdline setup. cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } } }) }) vim.cmd([[ set completeopt=menuone,noinsert,noselect highlight! default link CmpItemKind CmpItemMenuDefault ]]) end, }