local cmp = require 'cmp' local context = require 'cmp.config.context' local luasnip = require 'luasnip' vim.o.completeopt = nil -- General setup cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, window = { documentation = { border = 'rounded' }, }, formatting = { fields = { 'menu', 'abbr', 'kind' }, format = function(entry, item) item.menu = ({ nvim_lsp = 'λ', luasnip = '⋗', buffer = 'Ω', path = '🖫', })[entry.source.name] return item end, }, preselect = cmp.PreselectMode.None, mapping = { -- Confirm, jump or select with tab [''] = cmp.mapping(function(fallback) if cmp.get_selected_entry() then cmp.confirm() elseif luasnip.jumpable(1) then luasnip.jump(1) elseif luasnip.expandable() then luasnip.expand() elseif cmp.visible() then cmp.select_next_item() else fallback() end end, { 'i', 's' }), -- Jump back with shift tab [''] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { 'i', 's' }), -- Navigate options with ctrl-n and ctrl-p [''] = cmp.mapping(function(fallback) if not cmp.visible() then cmp.complete() else cmp.select_next_item() end end), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() else fallback() end end), }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'nvim_lua' }, }, { { name = 'buffer', keyword_length = 5 }, { name = 'path' }, }), completion = { keyword_length = 3 }, -- Disable in comments enabled = function() return not context.in_syntax_group('Comment') end, }