return { { "hrsh7th/cmp-nvim-lsp", -- "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "hrsh7th/cmp-cmdline", }, { "L3MON4D3/LuaSnip", dependencies = { "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets", }, }, { "hrsh7th/nvim-cmp", config = function() -- 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 luasnip = require("luasnip") local cmp = require("cmp") require("luasnip.loaders.from_vscode").lazy_load() local cmp_select = { behavior = cmp.SelectBehavior.Select } cmp.setup({ snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) -- For `luasnip` users. end, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_prev_item(cmp_select), [""] = cmp.mapping.select_next_item(cmp_select), [""] = cmp.mapping.confirm({ select = true }), -- [""] = cmp.mapping.abort(), [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), [""] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), -- [""] = cmp.mapping("lua require'luasnip'.jump(1)", { "i", "s" }), -- [""] = cmp.mapping("lua require'luasnip'.jump(-1)", { "i", "s" }), -- !!! -- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#no-snippet-plugin -- !!! -- [""] = cmp.mapping(function(fallback) -- if cmp.visible() then -- cmp.select_next_item() -- -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() -- -- that way you will only jump inside the snippet region -- 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(fallback) -- if cmp.visible() then -- cmp.select_prev_item() -- elseif luasnip.jumpable(-1) then -- luasnip.jump(-1) -- else -- fallback() -- end -- end, { "i", "s" }), }), sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "luasnip" }, { name = "path" }, }, { { name = "buffer" }, }, { { name = "nvim_lsp_signature_help" }, }), experimental = { chost_text = true, }, }) -- Enable completing paths in : cmp.setup.cmdline(":", { sources = cmp.config.sources({ { name = "path" }, }), }) end, }, }