local cmp = require'cmp' local snippy = require('snippy') cmp.setup({ snippet = { expand = function(args) snippy.expand_snippet(args.body) end }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. [''] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif snippy.can_expand_or_advance() then snippy.expand_or_advance() else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif snippy.can_jump(-1) then snippy.previous() else fallback() end end, { "i", "s" }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'snippy' }, { name = 'buffer' }, }), formatting = { fields = { cmp.ItemField.Abbr, cmp.ItemField.Kind, cmp.ItemField.Menu, }, format = function(entry, vim_item) vim_item.abbr = string.sub(vim_item.abbr, 1, 20) vim_item.kind = string.sub(vim_item.kind, 1, 10) -- vim_item.menu = string.sub(vim_item.menu, 1, 10) return vim_item end } })