-- Install and configure nvim-cmp to provide completion -- Install nvim-cmp and dependencies return { "hrsh7th/nvim-cmp", event = { "InsertEnter", "CmdlineEnter" }, dependencies = { -- Adds completion capabilities for text in buffers "hrsh7th/cmp-buffer", -- Adds path completion capabilities "hrsh7th/cmp-path", -- Adds vim cmdline completion capabilities "hrsh7th/cmp-cmdline", -- Snippet Engine & its associated nvim-cmp source { "L3MON4D3/LuaSnip", -- Follow latest release version = "v2.*", -- Install jsregexp (optional) build = "make install_jsregexp", }, "saadparwaiz1/cmp_luasnip", -- Adds a number of user-friendly snippets "rafamadriz/friendly-snippets", -- Adds emoji completion after ':' (to be evaluated) "hrsh7th/cmp-emoji", -- vs-code pictrograms "onsails/lspkind.nvim", }, -- Configure nvim-cmp config = function() local cmp = require("cmp") local luasnip = require("luasnip") local lspkind = require("lspkind") luasnip.config.setup { -- Extend markdown snippets to pandoc filetype -- https://github.com/L3MON4D3/LuaSnip/issues/132#issuecomment-1101710309 snippets = { markdown = {}, }, luasnip.filetype_extend("pandoc", {"markdown"}), } -- Load snippets from ~/.config/nvim/my_snippets/ require("luasnip.loaders.from_lua").lazy_load( {paths = "~/.config/nvim/my_snippets/"} ) require("luasnip.loaders.from_vscode").lazy_load() cmp.setup({ completion = { completeopt = "menu,menuone,preview,noselect", }, snippet = { -- on utilise luasnip comme moteur de snippets expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.scroll_docs(-1), [""] = cmp.mapping.scroll_docs(1), [""] = cmp.mapping.complete(), [""] = cmp.mapping.abort(), -- Insert current selection. -- `false` insert only explicitly selected items [""] = cmp.mapping.confirm({ select = true }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() else fallback() end end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.locally_jumpable(-1) then luasnip.jump(-1) else fallback() end end, { 'i', 's' }), }, -- Autocompletion sources sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "nvim_lua" }, { name = "lazydev" }, { name = "luasnip" }, -- snippets { name = "buffer", option = { keyword_length = 4, keyword_pattern = [[\k\+]], }, }, { name = "path" }, { name = "emoji" }, }), formatting = { -- Default behavior expandable_indicator = true, -- Default display fields fields = { "abbr", "kind", "menu" }, format = lspkind.cmp_format({ mode = "symbol_text", -- Each entry is prefixed by it's type menu = { nvim_lsp = "[LSP]", buffer = "[Buffer]", luasnip = "[LuaSnip]", nvim_lua = "[Lua]", lazydev = "[Lazydev]", path = "[Path]", emoji = "[Emoji]", }, }), }, }) end, }