blink.cmp
blink.cmp copied to clipboard
Keymap not work with plugin vim-visual-multi
Make sure you have done the following
- [X] I have updated to the latest version of
blink.cmp - [X] I have read the README
Bug Description
The keymap becomes ineffective in Vim-Visual-Multi mode. When entering multi-cursor editing mode with Vim-Visual-Multi, if a completion menu pops up and any keymap is used (e.g., pressing Enter to select the current item), the keymap stops working. Furthermore, even after exiting Vim-Visual-Multi's multi-cursor mode, the keymap remains broken, requiring a restart of Neovim to restore functionality.
Relevant configuration
No response
neovim version
NVIM v0.10.2 Build type: RelWithDebInfo LuaJIT 2.1.1727870382
blink.cmp version: branch, tag, or commit
main
Presumably you're using the keymap.preset = "enter" if I'm guessing right. You should change the mapping of vim-visual-multi to something else. Something like the following
{
"mg979/vim-visual-multi",
init = function()
vim.g.VM_theme = "purplegray"
vim.g.VM_mouse_mappings = 1
-- vim.schedule(function()
vim.g.VM_maps = {
["I BS"] = "",
["Goto Next"] = "]v",
["Goto Prev"] = "[v",
["I CtrlB"] = "<M-b>",
["I CtrlF"] = "<M-f>",
["I Return"] = "<S-CR>",
["I Down Arrow"] = "",
["I Up Arrow"] = "",
}
-- end)
end,
},
I'm not sure if the vim.schedule is actually needed. I read somewhere about it, but for me it works without vim.schedule as well (try to see what works for you). This way I remap the <CR> of vim-visual-multi to something else and am able to accept suggestions from blink.cmp.
Without this I also experienced the same problem you described, but that is because when you enter vim-visual-multi mode the mapping <CR> gets overwritten by vim-visual-multi and then you can't use it any more with blink.cmp.
@dpetka2001 Thank you, this works for me.
This should also help in fixing the blink mappings after exiting visual-multi, in case VM_custom_motions is used for custom mappings:
vim.api.nvim_create_autocmd("User", {
pattern = "visual_multi_exit",
callback = function()
local keymaps = vim.api.nvim_buf_get_keymap(0, "i")
for _, map in ipairs(keymaps) do
if map.desc == "blink.cmp" then
vim.keymap.del("i", map.lhs, { buffer = 0 })
end
end
require("blink.cmp.keymap.apply").keymap_to_current_buffer({
["<C-Space>"] = { "show", "show_documentation", "hide_documentation" },
["<C-c>"] = { "cancel", "fallback" },
["<Esc>"] = { "cancel", "fallback" },
["<CR>"] = { "select_and_accept", "fallback" },
["<Tab>"] = { "select_and_accept", "snippet_forward", "fallback" },
["<S-Tab>"] = { "snippet_backward", "fallback" },
["<Up>"] = { "select_prev", "fallback" },
["<Down>"] = { "select_next", "fallback" },
["<Right>"] = { "select_and_accept", "fallback" },
["<C-S-Up>"] = {
function(cmp)
cmp.scroll_documentation_up(3)
end,
"fallback",
},
["<C-S-Down>"] = {
function(cmp)
cmp.scroll_documentation_down(3)
end,
"fallback",
},
})
end,
})
This would basically reset the mappings blink.cmp creates, after exiting visual-multi mode.
If, right after entering Neovim, you switch to insert mode and blink.cmp is already configured, pressing Ctrl+Up/Down to enter multi-selection may sometimes select three lines. In my tests, the <CR> key could not replace correctly. You can try vim.g.VM_show_warnings = 0 to disable the warning messages, and after doing so, the functionality works as expected.