I’m currently rewriting my Neovim configuration using lua rather than using vimscript. I’m using the coc.nvim plugin and want to map return (<CR>
) to confirm completion.
The coc.nvim wiki has an entry to Use
inoremap <expr> <cr> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
As I’m still learning lua, it took me a little time to convert this Vimscript so I wanted to document my solution here.
vim.keymap.set(
'i',
'<CR>',
function()
if vim.fn['coc#pum#visible']() == 1 then
-- coc Pop Up Menu (pum) is visible, confirm selection
vim.fn['coc#pum#confirm']()
else
-- coco Pop Up Menu is not open, make no change to <CR>
return "<CR>"
end
end,
{ expr = true }
);
Leave a Reply