return { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "hrsh7th/cmp-cmdline", { "L3MON4D3/LuaSnip", -- follow latest release. version = "v2.*", -- Replace by the latest released major (first number of latest release) -- install jsregexp (optional!). build = "make install_jsregexp", dependencies = { "rafamadriz/friendly-snippets" }, }, "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets", { "hrsh7th/nvim-cmp", config = function() vim.opt.completeopt = { "menu", "menuone", "noselect" } local cmp = require("cmp") local luasnip = require("luasnip") local select_opts = { behavior = cmp.SelectBehavior.Select } cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, sources = { { name = "path" }, { name = "nvim_lsp", keyword_length = 1 }, { name = "buffer", keyword_length = 3 }, { name = "luasnip", keyword_length = 2 }, }, window = { documentation = cmp.config.window.bordered(), }, formatting = { fields = { "menu", "abbr", "kind" }, format = function(entry, item) local menu_icon = { nvim_lsp = "λ", luasnip = "⋗", buffer = "Ω", path = "🖫", } item.menu = menu_icon[entry.source.name] return item end, }, mapping = { [""] = cmp.mapping.select_prev_item(select_opts), [""] = cmp.mapping.select_next_item(select_opts), [""] = cmp.mapping.select_prev_item(select_opts), [""] = cmp.mapping.select_next_item(select_opts), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping.confirm({ select = false }), [""] = cmp.mapping(function(fallback) if luasnip.jumpable(1) then luasnip.jump(1) else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) local col = vim.fn.col(".") - 1 if cmp.visible() then cmp.select_next_item(select_opts) elseif col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then fallback() else cmp.complete() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item(select_opts) else fallback() end end, { "i", "s" }), }, }) end, }, }