Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120return { "hrsh7th/nvim-cmp", event = "VimEnter", dependencies = { "hrsh7th/cmp-buffer", -- source for text in buffer "hrsh7th/cmp-path", -- source for file system paths "hrsh7th/cmp-nvim-lsp-document-symbol", "hrsh7th/cmp-nvim-lsp-signature-help", { "hrsh7th/vim-vsnip", config = function() vim.g.vsnip_snippet_dir = "$XDG_CONFIG_HOME/nvim/snippets" vim.cmd [[ autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item) autocmd BufWritePre <buffer> lua vim.lsp.buf.format({}, 10000) ]] end, }, "hrsh7th/cmp-vsnip", "onsails/lspkind.nvim", -- vs-code like pictogram "hrsh7th/cmp-cmdline", }, config = function() local cmp = require("cmp") local lspkind = require("lspkind")
local has_words_before = function() unpack = unpack or table.unpack 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
cmp.setup({ window = { completion = cmp.config.window.bordered({ border = 'double', winhighlight = "Normal:CmpNormal", }), documentation = cmp.config.window.bordered({ border = 'double', winhighlight = "Normal:CmpDocNormal", }), }, snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, mapping = cmp.mapping.preset.insert({ ["<C-p>"] = cmp.mapping.select_prev_item(), ["<C-n>"] = cmp.mapping.select_next_item(), ['<C-l>'] = cmp.mapping.complete(), ['<C-e>'] = cmp.mapping.abort(), ['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-b>'] = cmp.mapping.scroll_docs(-4), ["<CR>"] = cmp.mapping.confirm { select = true },
["<Tab>"] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("<Plug>(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 `<Tab>`. end end, { "i", "s" }), ["<S-Tab>"] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("<Plug>(vsnip-jump-prev)", "") end end, { "i", "s" }), }), experimental = { ghost_text = true, }, sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = 'vsnip' }, { name = "buffer" }, { name = "path" }, }), }) -- `/` cmdline setup. cmp.setup.cmdline('/', { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) -- `:` cmdline setup. cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } } }) })
vim.cmd([[ set completeopt=menuone,noinsert,noselect highlight! default link CmpItemKind CmpItemMenuDefault ]]) end,}