local cmp = require'cmp' local luasnip = require'luasnip' local icons = { Text = "", Method = "", Function = "", Constructor = "", Field = "ﰠ", Variable = "", Class = "ﴯ", Interface = "", Module = "", Property = "ﰠ", Unit = "塞", Value = "", Enum = "", Keyword = "", Snippet = "", Color = "", File = "", Reference = "", Folder = "", EnumMember = "", Constant = "", Struct = "פּ", Event = "", Operator = "", } cmp.setup({ mapping = cmp.mapping.preset.insert({ [''] = cmp.get_config().mapping[''], [''] = cmp.get_config().mapping[''], [''] = function() luasnip.jump(1) end, [''] = function() luasnip.jump(-1) end, [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s" }), }), sources = { { name = "luasnip" }, { name = 'nvim_lsp' }, { name = 'buffer' }, { name = 'path' }, { name = 'orgmode' } }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, formatting = { fields = { 'menu', 'abbr', 'kind' }, format = function(entry, vim_item) -- Give the completion menu a consistent size to stop it jumping arround local width = 40 if #vim_item.abbr > width then vim_item.abbr = string.sub(vim_item.abbr, 1, width) else vim_item.abbr = vim_item.abbr .. string.rep(" ", width - #vim_item.abbr) end vim_item.menu = icons[vim_item.kind] or " " vim_item.kind = "(" .. entry.source.name .. ")" return vim_item end, }, experimental = { ghost_text = true, }, }) cmp.setup.cmdline(":", { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = "path" }, }, { { name = "cmdline" }, }), })