local cmp = require('cmp') local luasnip = require("luasnip") local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end local check_back_space = function() local col = vim.fn.col(".") - 1 return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil end cmp.setup { formatting = { format = function(entry, vim_item) -- fancy icons and a name of kind vim_item.kind = require("lspkind").presets.default[vim_item.kind] .. " " .. vim_item.kind -- set a name for each source vim_item.menu = ({ buffer = "[Buffer]", nvim_lsp = "[LSP]", ultisnips = "[UltiSnips]", nvim_lua = "[Lua]", cmp_tabnine = "[TabNine]", look = "[Look]", path = "[Path]", spell = "[Spell]", calc = "[Calc]", emoji = "[Emoji]" })[entry.source.name] return vim_item end }, mapping = { [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's'}), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }), [''] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }), [''] = cmp.mapping({ i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }), c = cmp.mapping.confirm({ select = false }), s = cmp.mapping.confirm({ select = false }), }), [""] = cmp.mapping(function(fallback) if luasnip.expand_or_jumpable() then vim.api.nvim_feedkeys(t("luasnip-expand-or-jump"), "", true) else fallback() end end, { "i", "s", }), [""] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then vim.api.nvim_feedkeys(t("luasnip-jump-prev"), "", true) else fallback() end end, { "i", "s", }), }, snippet = { expand = function(args) require'luasnip'.lsp_expand(args.body) end }, sources = { {name = 'nvim_lsp'}, {name = 'buffer'}, {name = "luasnip"}, {name = "nvim_lua"}, {name = "look"}, {name = "path"}, {name = 'cmp_tabnine'}, {name = "calc"}, {name = "spell"}, {name = "emoji"} }, completion = {completeopt = 'menu,menuone,noinsert, noselect'}, -- experimental = { native_menu = true } } -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline('/', { sources = { { name = 'buffer' } }, }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }, { { name = 'buffer' } }), }) -- Autopairs --require("nvim-autopairs.completion.cmp").setup({ -- map_cr = true, -- map_complete = true, -- auto_select = true --}) -- TabNine --local tabnine = require('cmp_tabnine.config') --tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true}) -- Database completion vim.api.nvim_exec([[ autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} }) ]], false)