return { { "saghen/blink.cmp", optional = true, enebled = false, }, { -- A completion plugin for neovim coded in Lua. "hrsh7th/nvim-cmp", version = false, event = { "InsertEnter", "CmdlineEnter" }, dependencies = { { "hrsh7th/cmp-nvim-lsp" }, { "hrsh7th/cmp-nvim-lsp-document-symbol" }, { "hrsh7th/cmp-nvim-lsp-signature-help" }, { "hrsh7th/cmp-buffer" }, { "hrsh7th/cmp-calc" }, { "hrsh7th/cmp-cmdline" }, { "dmitmel/cmp-cmdline-history" }, { "hrsh7th/cmp-emoji" }, { "hrsh7th/cmp-nvim-lua" }, { "hrsh7th/cmp-path" }, { "folke/lazydev.nvim" }, { "kdheepak/cmp-latex-symbols" }, { "saadparwaiz1/cmp_luasnip" }, { "ray-x/cmp-treesitter" }, }, opts = function() -- Register nvim-cmp lsp capabilities vim.lsp.config("*", { capabilities = require("cmp_nvim_lsp").default_capabilities() }) local icons = require("rc.core.config").icons local cmp_kinds = icons.kinds local cmp_menu = icons.cmp -- utility functions local has_words_before = function() 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 -- Configurations local cmp = require "cmp" local luasnip = require "luasnip" return { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, mapping = { [""] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert }, [""] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert }, [""] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select }, [""] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select }, [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.complete {}, { "i", "c" }), [""] = { i = cmp.mapping.abort(), c = cmp.mapping.close(), }, [""] = cmp.mapping { i = cmp.mapping.confirm { behavior = cmp.SelectBehavior.Replace, select = true }, c = cmp.mapping.confirm { select = false }, }, [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() 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" }), }, formatting = { format = function(entry, vim_item) -- Kind icons vim_item.kind = cmp_kinds[vim_item.kind] -- Source vim_item.menu = cmp_menu[entry.source.name] return vim_item end, }, sources = { { name = "nvim_lsp" }, { name = "buffer" }, { name = "calc" }, { name = "lazydev", group_index = 0 }, { name = "emoji" }, { name = "path" }, { name = "latex_symbols" }, { name = "luasnip" }, }, sorting = { comparators = { cmp.config.compare.offset, cmp.config.compare.exact, cmp.config.compare.score, -- Taken from https://github.com/lukas-reineke/cmp-under-comparator function(entry1, entry2) local _, entry1_under = entry1.completion_item.label:find "^_+" local _, entry2_under = entry2.completion_item.label:find "^_+" entry1_under = entry1_under or 0 entry2_under = entry2_under or 0 if entry1_under > entry2_under then return false elseif entry1_under < entry2_under then return true end end, cmp.config.compare.kind, cmp.config.compare.sort_text, cmp.config.compare.length, cmp.config.compare.order, }, }, } end, config = function(_, opts) -- Configurations local cmp = require "cmp" cmp.setup(opts) -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline("/", { sources = { { name = "buffer" }, }, }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(":", { sources = cmp.config.sources({ { name = "path" }, }, { { name = "cmdline" }, }), }) -- cmp-nvim -- local cmp_autopairs = require "nvim-autopairs.completion.cmp" -- cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } }) end, }, }