-- Configure Completion vim.opt.completeopt = {"menu","menuone","noselect"} vim.opt.shortmess:append "c" local ok, lspkind = pcall(require, "lspkind") if not ok then return end lspkind.init() local luasnip = require("luasnip") local cmp = require("cmp") local has_words_before = function() 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 cmp.setup { mapping = { [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "s" }), [""] = 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.select_next_item { behavior = cmp.SelectBehavior.Insert }, [""] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert }, [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping( cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Insert, select = true, }) }, sources = { {name = "nvim_lua"}, {name = "nvim_lsp"}, {name = "path"}, {name = "luasnip"}, { name = "buffer", option = { keyword_length = 5, }, }, }, snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end, }, experimental = { native_menu = false, ghost_text = true, }, formatting = { format = lspkind.cmp_format { mode = 'symbol_text', menu = { buffer = "[BUF]", nvim_lsp = "[LSP]", nvim_lua = "[API]", path = "[PTH]", luasnip = "[SNP]" } } } }