return { "hrsh7th/nvim-cmp", enabled = true, dependencies = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "hrsh7th/cmp-cmdline", --"hrsh7th/cmp-vsnip", --"saadparwaiz1/cmp_luasnip", "f3fora/cmp-spell", "hrsh7th/cmp-calc", "hrsh7th/cmp-emoji" }, config = function() -- Setup nvim-cmp. local cmp = require "cmp" local lspkind = require("lspkind") local capabilities = require('cmp_nvim_lsp').default_capabilities() --local luasnip = require('luasnip') local has_words_before = function() local line, col = 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 local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end require('lspconfig').sourcekit.setup { capabilities = capabilities } lspkind.init({ symbol_map = { Text = "", Method = "󰡱", Function = "󰡱", Constructor = "", Field = "ﰠ", Variable = "", Class = "ﴯ", Interface = "", Module = "", Property = "ﰠ", Unit = "塞", Value = "", Enum = "", Keyword = "", Snippet = "", Color = "", File = "", Reference = "", Folder = "", EnumMember = "", Constant = "", Struct = "פּ", Event = "", Operator = "", TypeParameter = "" } }) cmp.setup({ formatting = { format = lspkind.cmp_format { with_text = false, maxwidth = 50, menu = { buffer = "BUF", nvim_lsp = "LSP", path = "PATH", vsnip = "SNIP", calc = "CALC", spell = "SPELL", emoji = "EMOJI" } } }, experimental = {native_menu = false, ghost_text = false}, snippet = { expand = function(args) --require('luasnip').lsp_expand(args.body) end }, mapping = { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.close(), [""] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() -- elseif luasnip.expandable() then -- luasnip.expand() -- elseif luasnip.expand_or_jumpable() then -- luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() else fallback() end end, {"i", "s"}), [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() -- elseif vim.fn["vsnip#jumpable"](-1) == 1 then -- feedkey("(vsnip-jump-prev)", "") end end, {"i", "s"}) }, sources = { {name = "nvim_lsp"}, {name = "buffer", keyword_length = 5}, {name = 'luasnip', option = { show_autosnippets = true } }, {name = "calc"}, {name = "emoji"}, {name = "spell"}, {name = "path"} } }) -- Use buffer source for `/`. cmp.setup.cmdline("/", {sources = {{name = "buffer"}}}) -- Use cmdline & path source for ':'. cmp.setup.cmdline(":", { sources = cmp.config.sources({{name = "path"}}, {{name = "cmdline"}}) }) end }