local cmp = require('cmp') local luasnip = require('luasnip') local select_opts = { behavior = cmp.SelectBehavior.Select } local has_words_before = function() -- local line, col = unpack(vim.api.nvim_win_get_cursor(0)) local line, col = table.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 { enabled = true, preselect = cmp.PreselectMode.None, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end }, sources = { { name = 'path' }, { name = 'nvim_lsp' }, -- { name = 'buffer', keyword_length = 3 }, { name = 'buffer' }, { name = 'luasnip', keyword_length = 3 }, -- { name = 'cmdline' }, { name = "cmp_tabnine" }, { name = "nvim_lua" }, { name = 'buffer' }, { name = "neorg" }, }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.select_prev_item(select_opts), [''] = cmp.mapping.select_next_item(select_opts), [''] = cmp.mapping.select_next_item(select_opts), [''] = cmp.mapping.confirm({ select = true }), [''] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping.complete(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping(function(fallback) if luasnip.jumpable(1) then luasnip.jump(1) else fallback() end end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { 'i', 's' }) }), window = { documentation = cmp.config.window.bordered() }, formatting = { fields = { 'menu', 'abbr', 'kind' }, format = function(entry, item) local menu_icon = { nvim_lsp = '[lsp]', luasnip = '[snip]', buffer = '[buf]', path = '[path]', --cmdline = "[cmd]", cmp_tabnine = "[tab]", } item.menu = menu_icon[entry.source.name] return item end } } -- Use buffer source for `/` and `?` (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' } }) })