zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
31.11k stars 1.86k forks source link

Conflict with search history with text already entered at the prompt #678

Closed tapyu closed 1 year ago

tapyu commented 2 years ago

Describe the bug

Dears,

I am using the following snippet from a stack exchange answer:

autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end

This allows me to search through my history from the already entered text at the prompt. However, the zsh-autosuggestions plugin has conflicts with this snippet, which obligates me to press uparrow twice in order to search through the history

To Reproduce

  1. Put this snippet in the ~/.zshrc
  2. Check that you can search from the text already entered at the prompt pressing uparrow (just once per command)
  3. Install the zsh-autosuggestions plugin
  4. Notice that now you need to press the uparrow twice per command

Expected behavior

I would like to use the zsh-autosuggestions plugin and perform this search history in a minimal configuration. At the moment, I am using the joshskidmore/zsh-fzf-history-search plugin to make this task, but it is more desirable to use this snippet.

Anyone has an way out or can identify what is happening?

Desktop

 OS: Ubuntu 20.04 focal
 Kernel: x86_64 Linux 5.13.0-35-generic
 Shell: zsh 5.8
 DE: GNOME 3.36.5
 WM: Mutter
 CPU: Intel Core i7-9750H @ 12x 4.5GHz [44.0°C]
 GPU: Intel Corporation UHD Graphics 630 (Mobile)
NVIDIA Corporation GP107GLM [Quadro P620] (rev a1)
Plugin version: v0.7.0

Additional context

hongwen000 commented 2 years ago

Same problem, I had trouble browsing history using up arrow key, twice pressing is needed, and the anoying terminal bell always rings.

After all the search I found the issue #646 suggesting adding the two bindkey commands but did not work immediately for me. After that the issue #618 gave me a hint: following the direction, I identified that up arrow is encoded as ^[OA in my workstation.

Finally, the two lines of code solved my problem:

bindkey "^[OA" history-beginning-search-backward bindkey "^[OB" history-beginning-search-forward

pablospe commented 2 years ago

I also have this problem, the difference I am using Ctrl+P / Ctrl+N instead of the up/down arrows.

bindkey '^P' history-beginning-search-backward-end
bindkey '^N' history-beginning-search-forward-end

The suggestion @hongwen000 doesn't work for me. Notice that history-beginning-search-backward is different from history-beginning-search-backward-end (the -end). The cursor will stay in the end.

artudytu commented 2 years ago

I had to do modifications suggested here https://github.com/zsh-users/zsh-autosuggestions/issues/619#issuecomment-904193190 . After that not only that arrows worked after pressing just once, but it also resolved my issues with history. I could only go back like 5 commands and then it stopped working.

pablospe commented 2 years ago

Thanks!!! I confirm this solved the issue. I added:

ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-beginning-search-backward-end history-beginning-search-forward-end)
ericfreese commented 1 year ago

Closing as a duplicate of #619