return { "hrsh7th/nvim-cmp", event = "InsertEnter", dependencies = { "hrsh7th/cmp-buffer", -- source for text in buffer "hrsh7th/cmp-path", -- source for file system paths "hrsh7th/cmp-cmdline", -- source for command mode "saadparwaiz1/cmp_luasnip", -- for autocompletion "rafamadriz/friendly-snippets", -- useful snippets "onsails/lspkind.nvim", -- vs-code like pictograms { "L3MON4D3/LuaSnip", -- follow latest release of given major version = "v2.*", -- install jsregexp build = "make install_jsregexp", }, -- snippet engine }, config = function() local cmp = require("cmp") local luasnip = require("luasnip") local lspkind = require("lspkind") -- Loads vscode style snippets from installed plugins (e.g. friendly-snippets) require("luasnip.loaders.from_vscode").lazy_load() -- `/` 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", "!" }, }, }, }), }) -- Setup completion options and snippets and mappings cmp.setup({ -- Configure how the completion menu behaves -- menu: show menu -- menuone: show menu even when there is only one option -- preview: preview window explaining the offered completion -- select: select an option automatically (noselect is the reverse) completion = { completeopt = "menu,menuone,preview,select", }, -- Configure how nvim-cmp interacts with snippet engine snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_prev_item(), -- previous suggestion [""] = cmp.mapping.select_next_item(), -- next suggestion [""] = cmp.mapping.scroll_docs(-4), -- scroll down in docs [""] = cmp.mapping.scroll_docs(4), -- scroll up in docs [""] = cmp.mapping.scroll_docs(-4), -- scroll down in docs [""] = cmp.mapping.scroll_docs(4), -- scroll up in docs [""] = cmp.mapping.complete(), -- show completion suggestions [""] = cmp.mapping.abort(), -- close completion window [""] = cmp.mapping.complete({ config = { sources = { { name = "nvim_lsp" }, } }, }), -- show only lsp completions [""] = cmp.mapping(function(fallback) if cmp.visible() then if luasnip.expandable() then luasnip.expand() else cmp.confirm({ select = true, }) end else fallback() end end), -- On tab with completion open, go to next option [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.locally_jumpable(1) then luasnip.jump(1) else fallback() end end, { "i", "s", "c" }), -- On shift tab with completion open, go to prev option [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.locally_jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s", "c" }), }), -- Sources for autocompletion sources = cmp.config.sources({ { name = "nvim_lsp" }, -- lsp suggestions { name = "luasnip" }, -- snippets { name = "buffer" }, -- text within current buffer { name = "path" }, -- file system paths }), -- Configure lspkind for vs-code like pictograms in completion menu formatting = { format = lspkind.cmp_format({ maxwidth = 50, ellipsis_char = "...", show_labelDetails = true, }), }, }) end, }