Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using zvm_bindkey to bind widget to "ESC-<key>" renders backslash unusable #260

Open
3 tasks done
cohml opened this issue Jan 23, 2024 · 0 comments
Open
3 tasks done

Comments

@cohml
Copy link

cohml commented Jan 23, 2024

General information

  • Terminal program: iTerm.app 3.4.23 (xterm-256color)
  • Operating system: macOS 14.2.1 (23C71)
  • ZSH framework: oh-my-zsh master (f7b647e1)
  • ZSH version: zsh 5.9 (x86_64-apple-darwin23.0)
  • ZVM version: zsh-vi-mode 0.11.0

Basic examination

  • I have read through the README page
  • I have the latest version of zsh-vi-mode
  • I have tested with another terminal program

Problem description

The README states that custom widgets should be bound to a key (or key sequence) using zvm_bindkeys. However, in certain cases, zvm_bindkey can "steal" the first key of the sequence and bind it to zvm_readkeys_handler.

When the sequence begins with ESC - for which I believe the ANSI escape code is \e - this means that \ gets bound to zvm_readkeys_handler, making it impossible to type out a backslash.

After reading the source code, I'm quite certain the offending logic occurs here:

https://github.com/jeffreytse/zsh-vi-mode/blob/master/zsh-vi-mode.zsh#L608-L622C33

Reproduction steps

# define arbitrary functionfunction foo() {}
❯ 
❯ # register function as zsh widget
❯ zle -N foo
❯ 
❯ # note that zvm_readkeys_handler IS NOT bound to backslash
❯ bindkey -L | grep zvm_readkeys_handler
bindkey "^[" zvm_readkeys_handler
❯ 
❯ # note that i can still type backslashes\\\
❯ 
❯ # use zvm_bindkey to bind function to sequence beginning with backslash
❯ zvm_bindkey viins "\ef" foo
❯ 
❯ # note that zvm_readkeys_handler IS now bound to backslash
❯ bindkey -L | grep zvm_readkeys_handler
bindkey "^[" zvm_readkeys_handler
bindkey "\\\\" zvm_readkeys_handler
❯ 
❯ # i am unable to type backslashes
❯
❯ # when i try, it seems to try to register the subsequent key as a widget;# for example, here i will press "\f"
❯
No such widget `f'

Expected behavior

My widget should be bound to the specified sequence without rendering the initial key in the sequence unusable on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant