TabbyML / vim-tabby

Apache License 2.0
38 stars 2 forks source link

Wrong behavior when <tab> is already mapped #2

Closed lifepillar closed 7 months ago

lifepillar commented 7 months ago

Add this to your vimrc:

imap <tab> <nop>

When Vim is opened, <tab> is remapped by Tabby, which takes into account the existing mapping:

:verbose imap <tab>
i  <Tab>       & tabby#Accept("\<nop>")
        Last set from ~/.vim/pack/plugins/start/tabby/autoload/tabby/keybindings.vim line 19

But pressing Tab now may result in <nop> (the five-character string) being inserted literally into the buffer.

I noticed that because Tabby conflicts with my MUcomplete plugin, which maps <tab> to an internal plug. Then, pressing Tab inserts the plug literally into the buffer. For comparison, copilot.vim does not have this issue and coexists with MUcomplete without problems.

icycodes commented 7 months ago

Hi, @lifepillar,

Thank you for reporting this issue. I am trying to fix it via https://github.com/TabbyML/tabby/pull/763. Would you mind checking and testing it locally?

This PR adds checks for the script property of the original <tab> maparg and determines whether to add <script> to the imap command or not. For cases where <nop> is used, I haven't found a good solution yet, so I simply added a patch to check if the original <tab> maps to <nop> and do not fallback in that scenario.

lifepillar commented 7 months ago

Sorry, I didn't explain myself clearly enough. I've used <nop> as an example, but the idea is that if Tab is already mapped (in the case of MUcomplete, it is mapped to <plug>(MUcompleteFwd)), after Tabby remaps Tab the original mapping is added verbatim into the buffer when Tab is pressed.

I wasn't able to spot an obvious problem in the code, which is superficially very similar to copilot.vim's. But, for some reason, copilot.vim works as expected and Tabby doesn't.

icycodes commented 7 months ago

Sorry, I didn't explain myself clearly enough. I've used <nop> as an example, but the idea is that if Tab is already mapped (in the case of MUcomplete, it is mapped to <plug>(MUcompleteFwd)), after Tabby remaps Tab the original mapping is added verbatim into the buffer when Tab is pressed.

I wasn't able to spot an obvious problem in the code, which is superficially very similar to copilot.vim's. But, for some reason, copilot.vim works as expected and Tabby doesn't.

Thank you. The mentioned PR should address the bug when Tab is mapped to <plug>(MUcompleteFwd). It has been released in Tabby plugin v1.1.0. Could you please update the Tabby Plugin to the latest version and test it again to see if the issue is resolved?

lifepillar commented 7 months ago

I confirmed that the PR fixes the issue. I thought I had pulled it, but apparently I didn't it. Thank you very much!