2

I recently switched from vim to neovim.

I have the following keybindings in neovim:

vim.keymap.set("i", "0", "<Esc>la", { noremap = true }) 
vim.keymap.set("i", "00", "0", { noremap = true })  
vim.keymap.set("i", "[]", "{}<Esc>ha", { noremap = true })

Now when I press 0[] in quick succession, I expect the cursor to move one step forward and write {} with cursor inside the braces (this is how vim used to behave).

However, what I get is that the cursor moves one step forward and writes [] on the screen (instead of curly braces).

Can somebody see why this is the case?

2
  • 2
    I can reproduce the behavior but the first mapping is dangerous. If it used at the end of the line the l move will fail and the a will not be executed. Commented Jul 18, 2023 at 12:55
  • 1
    Thank you for the response? So is it indeed an unwanted behaviour or is it a feature of neovim? And you are right about the danger of the first mapping but I use it only for tex files and have used it for many years without problems. Can you make it better? Commented Jul 18, 2023 at 15:04

1 Answer 1

0

I would do:

vim.keymap.set("i", "0", "<C-o>l", { noremap = true })
vim.keymap.set("i", "00", "0", { noremap = true })
vim.keymap.set("i", "0[]", "<C-o>l{}<C-o>h", { noremap = true }) 
vim.keymap.set("i", "[]", "{}<C-o>h", { noremap = true }) 
2
  • 2
    I haven't tried this. But why do we need to separately map 0[]? Shouldn't neovim automatically execute the mapping for 0 and the mapping for [] one after the other when we press 0[]? Commented Jul 18, 2023 at 15:29
  • It seems that in Neovim the buffer waiting a disambiguation is pass as such to the mapping list. In your case 0[ do not match anything and is then output as such. If we add a mapping for 0[] then the disambiguation is resolved with the full string and it solves your problem (not nice but working :-| ) Commented Jul 18, 2023 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.