<CR> on mini.completion #1543
-
Contributing guidelines
Module(s)mini.completion QuestionIn documentary on ":h mini.completion", local keycode = vim.keycode or function(x)
return vim.api.nvim_replace_termcodes(x, true, true, true)
end
local keys = {
['cr'] = keycode('<CR>'),
['ctrl-y'] = keycode('<C-y>'),
['ctrl-y_cr'] = keycode('<C-y><CR>'),
}
_G.cr_action = function()
if vim.fn.pumvisible() ~= 0 then
-- If popup is visible, confirm selected item or add new line otherwise
local item_selected = vim.fn.complete_info()['selected'] ~= -1
return item_selected and keys['ctrl-y'] or keys['ctrl-y_cr']
else
-- If popup is not visible, use plain `<CR>`. You might want to customize
-- according to other plugins. For example, to use 'mini.pairs', replace
-- next line with `return require('mini.pairs').cr()`
return keys['cr']
end
end
vim.keymap.set('i', '<CR>', 'v:lua._G.cr_action()', { expr = true }) And it says, I followed this steps with copy-and-paste this. But "Enter" key does normal "" consistently. No select suggested. Am i missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Sorry, I don't really understand the issue. Would you mind elaborating a bit? Ideally, record a screencast of the behavior and post it here. Also, make sure that |
Beta Was this translation helpful? Give feedback.
-
I solved this with lazy-load "mini.pairs" |
Beta Was this translation helpful? Give feedback.
Sorry, I don't really understand the issue. Would you mind elaborating a bit? Ideally, record a screencast of the behavior and post it here.
Also, make sure that
<CR>
Insert mode mapping is not overridden with something else. For example, by 'mini.pairs'. To do that, execute:imap <CR>
and confirm that it showsv:lua._G.cr_action()
(and not something likev:lua.MiniPairs.cr()
). In case it does, take a look in the comment of the pasted code from 'mini.completion' help, and usereturn MiniPairs.cr()
(slightly better thanrequire('mini.pairs').cr()
) instead ofreturn keys['…