local has_words_before = function() if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then return false end 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 local lsp_symbols = { Text = "  (Text) ", Method = "  (Method)", Function = "  (Function)", Constructor = "  (Constructor)", Field = " ﴲ (Field)", Variable = "[] (Variable)", Class = "  (Class)", Interface = " ﰮ (Interface)", Module = "  (Module)", Property = " 襁 (Property)", Unit = "  (Unit)", Value = "  (Value)", Enum = " 練 (Enum)", Keyword = "  (Keyword)", Snippet = "  (Snippet)", Color = "  (Color)", File = "  (File)", Reference = "  (Reference)", Folder = "  (Folder)", EnumMember = "  (EnumMember)", Constant = " ﲀ (Constant)", Struct = " ﳤ (Struct)", Event = "  (Event)", Operator = "  (Operator)", TypeParameter = "  (TypeParameter)", } local cmp = require'cmp' cmp.setup{ completion = { completeopt = "menuone,noinsert,noselect", }, formatting = { format = function(entry, vim_item) -- fancy icons and a name of kind vim_item.kind = lsp_symbols[vim_item.kind] -- set a name for each source vim_item.menu = ({ buffer = "[Buffer]", nvim_lsp = "[LSP]", vsnip = "[vSnip]", path = "[Path]", spell = "[Spell]", })[entry.source.name] return vim_item end, }, snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, mapping = { -- [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Replace}), [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}), [""] = cmp.mapping(function(fallback) if vim.fn.pumvisible() == 1 then feedkey("", "n") elseif vim.fn["vsnip#available"]() == 1 then feedkey("(vsnip-expand-or-jump)", "") elseif has_words_before() then cmp.complete() else fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. end end, { "i", "s" }), [""] = cmp.mapping(function() if vim.fn.pumvisible() == 1 then feedkey("", "n") elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("(vsnip-jump-prev)", "") end end, { "i", "s" }), }, source = { { name = 'buffer' }, { name = 'vsnip' }, { name = 'path' }, { name = 'spell' }, } } vim.cmd [[autocmd FileType TelescopePrompt lua require('cmp').setup.buffer { enabled = false }]] vim.g.vsnip_snippet_dir = '~/.config/nvim/vsnips'