local Plugin = { "hrsh7th/nvim-cmp" } Plugin.dependencies = { -- Completion sources { "hrsh7th/cmp-buffer" }, { "hrsh7th/cmp-path" }, { "saadparwaiz1/cmp_luasnip" }, { "hrsh7th/cmp-nvim-lsp" }, -- Snippets { "L3MON4D3/LuaSnip" }, { "rafamadriz/friendly-snippets" }, } Plugin.event = "InsertEnter" function Plugin.config() local cmp = require("cmp") local luasnip = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() local select_opts = { behavior = cmp.SelectBehavior.Select } -- See :help cmp-config cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, sources = { { name = "path" }, { name = "nvim_lsp" }, { name = "buffer", keyword_length = 3 }, { name = "luasnip", keyword_length = 2 }, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, -- See :help cmp-mapping 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.select_prev_item(select_opts), }, }) end return Plugin