local M = {} function M.cmp_conf() local cmp = require('cmp') local luasnip = require('luasnip') local check_back_space = function() local col = vim.fn.col '.' - 1 return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil end local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end cmp.setup { formatting = { format = function(entry, vim_item) local lspkind_icons = { Text = '', Method = '', Function = '', Constructor = '', Field = 'ﰠ', Variable = '', Class = 'ﴯ', Interface = '', Module = '', Property = 'ﰠ', Unit = '塞', Value = '', Enum = '', Keyword = '', Snippet = '', Color = '', File = '', Reference = '', Folder = '', EnumMember = '', Constant = '', Struct = 'פּ', Event = '', Operator = '', TypeParameter = '' } -- load lspkind icons vim_item.kind = string.format('%s %s', lspkind_icons[vim_item.kind], vim_item.kind) vim_item.menu = ({ luasnip = '[SNIP]', path = '[PATH]', buffer = '[BUF]', -- calc = '[CALC]', -- nuspell = '[SPELL]', spell = '[SPELL]', emoji = '[EMOJI]', nvim_lsp = '[LSP]', latex_symbols = '[TEX]', tmux = '[TMUX]', orgmode = '[ORG]' })[entry.source.name] return vim_item end }, mapping = { [''] = cmp.mapping.complete(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.close(), -- supertab-like mapping [''] = cmp.mapping(function(fallback) if vim.fn.pumvisible() == 1 then vim.fn.feedkeys(t(''), 'n') elseif luasnip.expand_or_jumpable() then vim.fn.feedkeys(t('luasnip-expand-or-jump'), '') elseif check_back_space() then vim.fn.feedkeys(t(''), 'n') else fallback() end end, {'i', 's'}), [''] = cmp.mapping(function(fallback) if vim.fn.pumvisible() == 1 then vim.fn.feedkeys(t(''), 'n') elseif luasnip.jumpable(-1) then vim.fn.feedkeys(t('luasnip-jump-prev'), '') else fallback() end end, {'i', 's'}) }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end }, sources = { {name = 'luasnip'}, {name = 'path'}, {name = 'buffer'}, -- {name = 'calc'}, -- {name = 'nuspell'}, {name = 'spell'}, {name = 'emoji'}, {name = 'nvim_lsp'}, {name = 'latex_symbols'}, {name = 'tmux'}, {name = 'orgmode'} } } end function M.autopairs_conf() require('nvim-autopairs').setup {fast_wrap = {}} require('nvim-autopairs.completion.cmp').setup({ map_cr = true, -- map on insert mode map_complete = true, -- it will auto insert `(` after select function or method item auto_select = true -- automatically select the first item }) end function M.snippets_conf() require('luasnip').config.set_config({ updateevents = 'TextChanged, TextChangedI', history = true }) -- Loading vscode-like snippets from 'friendly-snippets' require('luasnip/loaders/from_vscode').load() end function M.coq_conf() -- To add snippets from lsp servers, change lsp.lua: ----- -- local coq = require('coq') -- lspconf..setup(...) --> lspconf..setup(coq.lsp_ensure_capabilities(...)) vim.g.coq_settings = { auto_start = true, display = { icons = { mode = 'none' } } } end function M.autotag_conf() require('nvim-treesitter.configs').setup { autotag = {enable = true} } end return M