zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.33k stars 1.85k forks source link

Issues with history #712

Open amalic opened 1 year ago

amalic commented 1 year ago

It seems to only parse the last 15 lines of the history file and constantly begins every page at the newest entry. Sometimes only a few entries (3-4) are shown, and when navigating to the top most shown entry suddenly other entries are displayed.

Update: I also realized that it displays mulitple history entries as one entry and sometimes even older history entries. between the newer ones.

Update2: I also realized that I have sometimes to press Ctrl+C multiple times to exit history preview

ericfreese commented 1 year ago

Hi, I'm not able to understand the problem you're describing.

Can you add steps to reproduce using this template

% zsh -df
% source path/to/zsh-autosuggestions.zsh
% ... # what do you do to reproduce?

Screenshots may also be helpful

0x303 commented 1 year ago

I have this same problem. I know what you're talking about. It is difficult to explain but I will do my best.

Let's say my zsh_history looks like this:

cd /etc
ls -la
echo "hello 12345"
echo "hello 123"
uname -a
cat /etc/hosts

If I want to re-run the command echo "hello 123". I type echo "h and there will be the option in the ghost text to complete the rest of the line ello 123". If I press the RIGHT arrow key, my cursor will go to the end of the line and now in my terminal I will have the full command echo "hello 123" ready to be run.

If I hit the UP arrow key, I will go to echo "hello 12345", since that also matches the same preceding characters in my zsh_history.

However, let's say I change my mind, I don't want to run the echo command at all, I instead want to use the UP arrow key to cycle through my history and rerun the last command I ran cat /etc/hosts.

Remember, echo "12345" is currently in my terminal typed out. I would expect that since there is no other history matches for echo "12345*" in my history (like there is not a history entry for echo "123456789") that hitting the UP arrow should just take me to cat /etc/hosts. But that is not what happens... The terminal is locked so I have to hit CTRL+C to cancel the command I have typed out and get a clean prompt, or I have to press DELETE enough times to clear the terminal before I can cycle through my history like normal.

It is incredibly frustrating because this is such a great plugin but it effectively overwrites the default ZSH behavior that is in place if you do not run this plugin. I think there has to be a way to tinker with the keybinds that this module creates so that the plugin can still provide the utility it intends to while still playing nice with the default behavior that users expect.

0x303 commented 1 year ago

Also, another thing I noticed: If you are cycling through your history with the UP and DOWN arrow keys, and then you hit the RIGHT arrow key to go to the end of the line, and then you hit the LEFT arrow key you will no longer be able to cycle through the remaining history. The LEFT arrow key seems to mess up the ability for you to continue searching through the history.

justamanm commented 6 months ago

same issue up/down arrow doesn't iterate history but stunned when already accept part of completion, as @0x303 says, it will try to match history instead switch to last/next history.

justamanm commented 6 months ago

after searching for a while, i reslove it. thought from another isuue, we can use below command to know which functionality is bound to up/down key

bindkey $terminfo[kcuu1]

output: "^[OA" up-line-or-beginning-search, the "^[OA" is up arrow. so the up arrow is default bound to up-line-or-beginning-search which maybe be same as history-beginning-search-forward

so, just change binding: up arrow to up-line-or-history, and down arrow to down-line-or-history

# .zshrc
# add this
bindkey '^[OA' up-line-or-history
bindkey '^[OB' down-line-or-history