local M = {} function M.cmp_conf() local cmp = require('cmp') local luasnip = require('luasnip') local has_words_before = function() local cursor = vim.api.nvim_win_get_cursor(0) return not vim.api.nvim_get_current_line():sub(1, cursor[2]):match('^%s$') 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]', -- treesitter = '[TS]', nvim_lsp = '[LSP]', -- cmp_tabnine = '[TN]', 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(), -- Change choice nodes for luasnip [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-prev-choice', true, true, true), '', true) else fallback() end end, {'i', 's'}), [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-next-choice', true, true, true), '', true) else fallback() end end, {'i', 's'}), -- supertab-like mapping [''] = cmp.mapping(function(fallback) if vim.fn.pumvisible() == 1 then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n', true) elseif has_words_before() and luasnip.expand_or_jumpable() then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '', true) else fallback() end end, {'i', 's'}), [''] = cmp.mapping(function(fallback) if vim.fn.pumvisible() == 1 then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n', true) elseif luasnip.jumpable(-1) then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-jump-prev', true, true, true), '', true) 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 = 'treesitter'}, {name = 'nvim_lsp'}, -- {name = 'cmp_tabnine'}, {name = 'conjure'}, {name = 'latex_symbols'}, {name = 'tmux'}, {name = 'orgmode'} } } end -- function M.tabnine_conf() -- local tabnine = require('cmp_tabnine.config') -- tabnine:setup({ -- max_lines = 1000, -- max_num_results = 20, -- sort = true, -- run_on_every_keystroke = true -- }) -- 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() local types = require('luasnip.util.types') require('luasnip').config.set_config({ updateevents = 'TextChanged, TextChangedI', history = true, ext_opts = { [types.choiceNode] = { active = { virt_text = {{'●', 'Orange'}} } }, [types.insertNode] = { active = { virt_text = {{'●', 'Blue'}} } } } }) -- 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-ts-autotag').setup({ filetypes = { 'html', 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'svelte', 'vue' } }) end return M