diff --git a/lua/cosmic/plugins/nvim-cmp/init.lua b/lua/cosmic/plugins/nvim-cmp/init.lua index 78e9230..b52e12e 100644 --- a/lua/cosmic/plugins/nvim-cmp/init.lua +++ b/lua/cosmic/plugins/nvim-cmp/init.lua @@ -10,12 +10,22 @@ local has_words_before = function() end local default_cmp_opts = { + enabled = function() + -- disable completion in comments + local context = require('cmp.config.context') + -- keep command mode completion enabled when cursor is in a comment + if vim.api.nvim_get_mode().mode == 'c' then + return true + else + return not context.in_treesitter_capture('comment') and not context.in_syntax_group('Comment') + end + end, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, - mapping = { + mapping = cmp.mapping.preset.insert({ [''] = 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' }), @@ -54,10 +64,12 @@ local default_cmp_opts = { 'i', 's', }), - }, - documentation = { - border = user_config.border, - winhighlight = 'FloatBorder:FloatBorder,Normal:Normal', + }), + window = { + documentation = { + border = user_config.border, + winhighlight = 'FloatBorder:FloatBorder,Normal:Normal', + }, }, experimental = { ghost_text = true, @@ -97,6 +109,7 @@ vim.api.nvim_create_autocmd('FileType', { cmp.setup(u.merge(default_cmp_opts, user_config.nvim_cmp or {})) cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' }, }, @@ -112,6 +125,7 @@ cmp.setup.filetype('gitcommit', { }) -- cmp.setup.cmdline(':', { +-- mapping = cmp.mapping.preset.cmdline(), -- sources = cmp.config.sources({ -- { name = 'path' }, -- }, {