jeffreytse / zsh-vi-mode

💻 A better and friendly vi(vim) mode plugin for ZSH.
MIT License
2.94k stars 102 forks source link

Strange behaviour with zsh-autosuggestion key bindings #202

Open Praful opened 1 year ago

Praful commented 1 year ago

General information

Please report the following information as possible as you can:

Basic examination

Problem description

Before installing zsh-vi-mode, I had the following lines in my .zshrc file:

bindkey '^o' forward-char
bindkey '^w' forward-word

These defined keystrokes for zsh-autosuggestion.

After installing zsh-vi-mode, the second keybinding (^w) didn't work. I followed the instructions and created the following in my .zshrc:

function zvm_after_lazy_keybindings() {
  zvm_bindkey viins '^o' forward-char
  zvm_bindkey viins '^w' forward-word
}

These didn't work initially. If I use the default alternative key for forward-char (which is right arrow) that works. After using the right arrow key, both the above bindings work! bindkey confirms the definitions for ^o and ^w have changed after using the right arrow key.

Reproduction steps

  1. Install zsh-autosuggestion.
  2. Define function zvm_after_lazy_keybindings() as above.
  3. Open terminal and check keybindings using bindkey.
  4. In a terminal, start typing a command. When a suggestion appears, press ^o to accept the line. ^O appears instead of the cursor moving to the end of the suggestion.
  5. Delete the ^o.
  6. Press the right arrow key. The cursor moves to the end of the suggestion.
  7. Start a new command.
  8. When a suggestion appears, press ^o or ^w. Both work.
  9. Check keybindings using bindkey. They are different from those seen in step 3 for ^o and ^w.

Expected behavior

After defining ^o and ^w as above, pressing ^o should take the cursor to the end of the suggestion. ^w should take the cursor to the end of the next word.

gennaro-tedesco commented 1 year ago

I also have problems with zsh-autosuggestion, namely whichever key is bound to select the proposed suggestion (normally the arrow up/down keys) stops working when using this plugin.

What is the recommended way to complete the selected zsh-autosuggestion when using this?

loxosceles commented 9 months ago

I would be very interested in a solution here as well. When I don't have zsh-vi-mode installed, my keybinding to accept an autosuggestion works flawlessly. It stops working as soon as I enable vi-mode. (The default vi-mode of zsh does work however).

This is the keybinding:

bindkey '^ ' autosuggest-accept

Interestingly, if I source my .zshrc it works afterwards.