diff options
| author | Robert Günzler <r@gnzler.io> | 2022-11-04 16:48:47 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2022-11-18 18:37:25 +0100 |
| commit | d8723298b6fc04897f18af138d1b01c3581b5b97 (patch) | |
| tree | 7d035ab162d7b8457855e2fddaea217e8f78841d /.vim/lua | |
| parent | beeac96fee25e3b59886e556e090984059ad57e0 (diff) | |
vim: modernize cmp config
Diffstat (limited to '.vim/lua')
| -rw-r--r-- | .vim/lua/plugins.lua | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index 3e61292..711d4cf 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -495,9 +495,16 @@ require('packer').startup({function() local cmp = require('cmp') local luasnip = require('luasnip') cmp.setup { - completion = { - -- autocomplete = { cmp.TriggerEvent.TextChanged } - }, + -- disable completion in comments + enabled = function() + local ctx = require('cmp.config.context') + if vim.api.nvim_get_mode().mode == 'c' then + return true + else + return ctx.in_treesitter_capture('comment') + and not ctx.in_syntax_group('Comment') + end + end, preselect = cmp.PreselectMode.Item, window = { documentation = { @@ -507,7 +514,7 @@ require('packer').startup({function() mapping = { -- {{{2 ['<cr>'] = cmp.mapping(function(fallback) if cmp.visible() then - cmp.confirm({ select = true }) + cmp.mapping.confirm({ select = true }) elseif luasnip.expandable() then luasnip.expand() else @@ -515,10 +522,6 @@ require('packer').startup({function() end end), ['<c-space>'] = cmp.mapping.complete(), - ['<c-e>'] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), ['<c-n>'] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() @@ -540,7 +543,7 @@ require('packer').startup({function() ['<tab>'] = cmp.mapping({ i = function(fallback) if cmp.visible() then - cmp.confirm({ select = true }) + cmp.mapping.confirm({ select = true }) elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() else @@ -644,22 +647,22 @@ require('packer').startup({function() end, }, } - cmp.setup.cmdline('/', { - sources = cmp.config.sources({ - { name = 'nvim_lsp_document_symbol' } - }, { + cmp.setup.cmdline({'/', '?', '@'}, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'nvim_lsp_document_symbol' }, { name = 'buffer' } - }), + }, formatting = { fields = {'abbr', 'menu'}, }, }) cmp.setup.cmdline(':', { - sources = cmp.config.sources({ - { name = 'path' } - }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'path' }, { name = 'cmdline' } - }), + }, formatting = { fields = {'abbr', 'menu'}, }, @@ -667,7 +670,7 @@ require('packer').startup({function() -- insert `(` after selecting function/method items cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm_done { - map_char = { tex = '' } + map_char = {tex = ''} }) end} -- }}} |