|
| 1 | +local lspkind = require'lspkind' |
| 2 | +local source_mapping = { |
| 3 | + buffer = "[Buffer]", |
| 4 | + nvim_lsp = "[LSP]", |
| 5 | + nvim_lua = "[Lua]", |
| 6 | + cmp_tabnine = "[TN]", |
| 7 | + path = "[Path]", |
| 8 | + vsnip = "[vsnip]", |
| 9 | + cmdline = "[cmdline]" |
| 10 | +} |
| 11 | +local cmp = require'cmp' |
| 12 | + cmp.setup({ |
| 13 | + formatting = { |
| 14 | + format = lspkind.cmp_format({ |
| 15 | + maxwidth = 50, |
| 16 | + before = function (entry, vim_item) |
| 17 | + vim_item.menu = source_mapping[entry.source.name] |
| 18 | + return vim_item |
| 19 | + end |
| 20 | + }), |
| 21 | + }, |
| 22 | + snippet = { |
| 23 | + expand = function(args) |
| 24 | + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. |
| 25 | + end, |
| 26 | + }, |
| 27 | + mapping = cmp.mapping.preset.insert({ |
| 28 | + ['<C-j>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), |
| 29 | + ['<C-k>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), |
| 30 | + ['<C-e>'] = cmp.mapping.close(), |
| 31 | + ['<CR>'] = cmp.mapping.confirm({ select = true }), |
| 32 | + }), |
| 33 | + sources = cmp.config.sources({ |
| 34 | + { name = 'nvim_lsp' }, |
| 35 | + { name = 'vsnip' }, |
| 36 | + { name = 'path' }, |
| 37 | + { name = 'buffer' } |
| 38 | + }) |
| 39 | + }) |
| 40 | + |
| 41 | + -- Set configuration for specific filetype. |
| 42 | + cmp.setup.filetype('gitcommit', { |
| 43 | + sources = cmp.config.sources({ |
| 44 | + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. |
| 45 | + }, { |
| 46 | + { name = 'buffer' }, |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). |
| 51 | + cmp.setup.cmdline('/', { |
| 52 | + mapping = cmp.mapping.preset.cmdline(), |
| 53 | + sources = { |
| 54 | + { name = 'buffer' } |
| 55 | + } |
| 56 | + }) |
| 57 | + |
| 58 | + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). |
| 59 | + cmp.setup.cmdline(':', { |
| 60 | + mapping = cmp.mapping.preset.cmdline(), |
| 61 | + sources = cmp.config.sources({ |
| 62 | + { name = 'path' } |
| 63 | + }, { |
| 64 | + { name = 'cmdline' } |
| 65 | + }) |
| 66 | + }) |
0 commit comments