Close completion with Escape key, but remain in Insert mode? #924
-
I'd like to be able to close nvim-cmp's completion menu with Is this possible? Current mapping = {
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
["<S-Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
} Tried adding this to the above (didn't work, exited Insert mode): ["<Esc>"] = cmp.mapping.abort(), And this (didn't work, still exited Insert mode): ["<Esc>"] = function(fallback)
if cmp.visible() then
cmp.mapping.close()
else
fallback()
end
end, I kinda thought this last one was gonna work, but looking back at it, I'm just calling a mapping on that line. However, to debug things, I changed |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Would |
Beta Was this translation helpful? Give feedback.
-
Do your My configuration is in fennel but I've used the following for months: (local m cmp.mapping)
(local visible? cmp.visible)
(local abort! cmp.abort)
{:mapping {:<esc> (m #(if (visible?) (abort!) ($)) [:i :c])}} The function is basically identical to the last one in your post except it uses abort instead of close. |
Beta Was this translation helpful? Give feedback.
-
Yes, avoid |
Beta Was this translation helpful? Give feedback.
-
@pbar1 You can use nvim_feedkeys for that. |
Beta Was this translation helpful? Give feedback.
Do your
<tab>
/<s-tab>
maps work? I think functions need to be wrapped incmp.mapping(fn)
to work properly.My configuration is in fennel but I've used the following for months:
The function is basically identical to the last one in your post except it uses abort instead of close.