jake-stewart / multicursor.nvim

multiple cursors in neovim
MIT License
574 stars 4 forks source link

Insert mapping with multiple character output has the output duplicated if the input character exists in the output string #44

Closed RAV64 closed 1 week ago

RAV64 commented 1 week ago

https://github.com/user-attachments/assets/ff5b76a1-0236-473a-b6f6-24d711b91e26

As the video shows, in insert mode keymapping where the input character exists in the output string - multicursors duplicate the output string after the input character.

a should become ab but becomes abb q should become qwe but becomes qwewe

This is a problem since I have a keymapping in insert mode which translates "(" into "()\", so none of my auto pairs work with multicursors currently.

https://github.com/user-attachments/assets/d8e4dadb-131e-4290-ac5f-cd3df645d56c

The output is strangely multiplied on both ends of the string when the initial letter exists in the middle of the output string 😅

jake-stewart commented 1 week ago

fixed. let me know if any problems. thanks for opening the issue

jake-stewart commented 1 week ago

btw, i'm not sure if a mapping like inoremap ( ()<left> is possible. even without multicursors installed, pressing . after typing hello(foo only repeats the foo.

will have to ponder this

jake-stewart commented 1 week ago

i just tried an autopairs plugin and it successfully sets the . register for us, so it works for multicursor. hooray !!

RAV64 commented 1 week ago

Amazing work - Thank you! Your reservation about the dot-repeat was absolutely correct. I've solved this on my end by doing this hacky thing I stole from mini.pairs.

local function escape(s)
    return vim.api.nvim_replace_termcodes(s, true, true, true)
end

local left = escape("<C-g>U") .. escape("<left>")

And for the keymap I've set replace_keycodes = false

Both the multicursor and dot-repeat work as expected now 👍🏻