-- Author : swytch -- Created : Saturday Sept. 11, 2021 22:12:33 CET -- License : GPLv3 -- Description : cmp plugin config file local cmp = require("cmp") local luasnip = require("luasnip") 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 -- Custom item icons local icons = { } cmp.setup { completion = { autocomplete = true }, sources = { { name = "path" }, { name = "luasnip" }, { name = "nvim_lsp" }, { name = "buffer" }, { name = "nvim_lua" }, { name = "calc" }, { name = "spell" }, { name = "treesitter" }, }, formatting = { format = function(entry, vim_item) vim_item.menu = ({ nvim_lsp = "[lsp]", nvim_lua = "[nvim]", luasnip = "[snip]", path = "[path]", buffer = "[buff]", calc = "[calc]", spell = "[spel]", treesitter = "[tree]", })[entry.source.name] return vim_item end, }, snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end, }, mapping = { [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.close(), [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true, }), [""] = cmp.mapping(function(fallback) if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() 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) if cmp.visible() then cmp.select_next_item() 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() else fallback() end end, { "i", "s" }), }, view = { entries = {name = 'custom', selection_order = 'near_cursor' } }, }