-- Setup nvim-cmp. local cmp = require("cmp") local lspkind = require("lspkind") cmp.setup({ formatting = { format = lspkind.cmp_format({ with_text = false, maxwidth = 50, mode = "symbol", menu = { buffer = "BUF", rg = "RG", nvim_lsp = "LSP", path = "PATH", luasnip = "SNIP", calc = "CALC", spell = "SPELL", }, }), }, snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end, }, mapping = { [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.close(), [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false, }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() end end, { "i", "s" }), }, sources = { { name = "nvim_lsp" }, { name = "nvim_lsp_signature_help" }, { name = "buffer", keyword_length = 5 }, { name = "luasnip" }, { name = "calc" }, { name = "spell", keyword_length = 5 }, { name = "path" }, { name = "rg", keyword_length = 5 }, }, }) -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline("/", { mapping = cmp.mapping.preset.cmdline(), sources = { { 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 = cmp.config.sources({ { name = "path" }, }, { { name = "cmdline" }, }), })