diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index 4e05e13..49076ad 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -105,7 +105,19 @@ return { -- 命令栏补全(Tab 导航,回车无选择时直接执行) require('cmp').setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), + mapping = { + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'c' }), + [''] = cmp.mapping({ + c = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ select = false }) + else + fallback() + end + end, + }), + }, sources = { { name = 'cmdline' }, { name = 'path' }, @@ -114,7 +126,19 @@ return { -- 搜索栏补全 require('cmp').setup.cmdline('/', { - mapping = cmp.mapping.preset.cmdline(), + mapping = { + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'c' }), + [''] = cmp.mapping({ + c = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ select = false }) + else + fallback() + end + end, + }), + }, sources = { { name = 'buffer' }, }