jeffreytse / zsh-vi-mode

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

Arrow key does not do prefix-based history completion #266

Open ahmetb opened 4 months ago

ahmetb commented 4 months ago

General information

Basic examination

Problem description

Without enabling zsh-vi-mode, if I type curl and press ⬆️ key on my keyboard, I get the last command executed with curl prefix (and successive hits to ⬆️ ⬇️ cycles between those only).

However if I enable zsh-vi-mode, type curl and hit ⬆️ , I only get the last executed command (doesn't start with curl). What would be the reason for that?

Reproduction steps

  1. enable zsh-vi-mode
  2. type curl
  3. press up arrow key
  4. prompt now has the last executed command that doesn't start with curl...

Expected behavior

By default zsh (or maybe something else I installed) ensures only commands with curl prefix are provided based on up/down arrow keys.

munhoshi commented 4 months ago

I'm experiencing the exact same behavior on kitty 0.21.2.

thdonatello commented 4 months ago

I added

function zvm_before_lazy_keybindings() {
  bindkey -M vicmd '^[[A' history-search-backward
  bindkey -M viins '^[[A' history-search-backward
  bindkey -M vicmd '^[[B' history-search-forward
  bindkey -M viins '^[[B' history-search-forward
}

in my .zshrc But it works after the first time I enter the normal mode. It works fine if I add

zvm_bindkey vicmd '^[[A' history-search-backward
zvm_bindkey viins '^[[A' history-search-backward
zvm_bindkey vicmd '^[[B' history-search-forward
zvm_bindkey viins '^[[B' history-search-forward

in my zsh-vi-mode.zsh

Arethusag commented 4 months ago

I have this same issue on wezterm, I modified @thdonatello's suggestion and it worked great. I ended up using this in my .zshrc

zvm_bindkey vicmd "${terminfo[kcuu1]}" up-line-or-history
zvm_bindkey viins "${terminfo[kcuu1]}" up-line-or-history
zvm_bindkey vicmd "${terminfo[kcud1]}" down-line-or-history
zvm_bindkey viins "${terminfo[kcud1]}" down-line-or-history

Is it intended that zsh-vi-mode is overriding the default up and down arrow bindings?

thdonatello commented 4 months ago

I found this and it works for me