diff --git a/config/plugins/nvim-cmp.vim b/config/plugins/nvim-cmp.vim index d672e3448..323fed239 100644 --- a/config/plugins/nvim-cmp.vim +++ b/config/plugins/nvim-cmp.vim @@ -1,33 +1 @@ -" we are using https://github.com/hrsh7th/nvim-cmp/tree/3192a0c57837c1ec5bf298e4f3ec984c7d2d60c0 - -lua <'] = 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' }), - [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. - [''] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'path' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = 'buffer' }, - }) - }) - - -- Setup lspconfig. - local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -- Replace with each lsp server you've enabled. -EOF +lua require('config.nvim-cmp') diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua new file mode 100644 index 000000000..723fb6a99 --- /dev/null +++ b/lua/config/nvim-cmp.lua @@ -0,0 +1,41 @@ +local cmp = require('cmp') + +cmp.setup({ + mapping = { + [''] = 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' }), + [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'path' }, + { name = 'neosnippet' }, + }, { + { name = 'buffer' }, + }), +}) + +-- Setup lspconfig. +local capabilities = + require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +-- Replace with each lsp server you've enabled.