How to disable Enter to accept suggestion on with completeopt=noinsert #2125
-
Contributing guidelines
Module(s)mini.completion QuestionI like to have the first item selected by default so that as soon as I press <C-y> it's accepted. I recently changed to local function helper_pum(lhs)
local info = vim.fn.complete_info({"selected", "pum_visible"})
-- vim.notify(tostring(info.pum_visible) .. tostring(info.selected == -1) .. '\n', vim.log.levels.ERROR)
if (info.pum_visible) and (info.selected == -1) then
return '<C-n>' .. lhs
end
return lhs
end
map("i", "<C-y>", function() return helper_pum('<C-y>') end, {expr = true})
map("i", "<C-n>", function() return helper_pum("<C-n>") end, {expr = true})This works fine enough with <C-y> but is not even triggered for <C-n> (the vim.notify is not displayed) only when the popup menu is active, seems to work fine otherwise. My question is first: Is there a less hacky way to make this work with noinsert? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Can you please clarify what would you like to happen when pressing vim.keymap.set('i', '<CR>', [[pumvisible() ? "\<C-e>\<CR>" : "\<CR>"]], { expr = true })You can also utilize local pmenu_dismiss = {
condition = function() return vim.fn.pumvisible() == 1 end,
action = function() return '<C-e><CR>' end,
}
MiniKeymap.map_multistep('i', '<CR>', { pmenu_dismiss, 'minipairs_cr' })Does this answer your question? |
Beta Was this translation helpful? Give feedback.
Can you please clarify what would you like to happen when pressing
<CR>when there is a pmenu visible? Is it basically "hide pmenu and start new line"? If yes, then this can be achieved with custom<CR>mapping in Insert mode. Something like this:You can also utilize
MiniKeymap.map_multistep()to make it work with other uses of<CR>. Something like this: