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

zle widget based on insert-last-word no longer works as expected #748

Open
Amar1729 opened this issue Jul 2, 2023 · 2 comments
Open

zle widget based on insert-last-word no longer works as expected #748

Amar1729 opened this issue Jul 2, 2023 · 2 comments
Labels

Comments

@Amar1729
Copy link

Amar1729 commented Jul 2, 2023

Describe the bug

I have the following widget defined and bound in my rc (copied from this stackoverflow post):

insert-first-word () { zle insert-last-word -- -1 1 }
zle -N insert-first-word
bindkey '^[,' insert-first-word

This used to work as expected: when pressing alt + , (or escape ,), zsh would insert the first word of the previous command. However, it now inserts the last word of the previous command (commonly ^[., or insert-last-word (no argument)).

To Reproduce

Steps to reproduce the behavior:

% zsh -df
% source path/to/zsh-autosuggestions.zsh

# bind m+. (for comparison)
% bindkey '^[.' insert-last-word

# create widget and bind m+,
% insert-first-word () { zle insert-last-word -- -1 1 }
% zle -N insert-first-word
% bindkey '^[,' insert-first-word

# some command with arguments
% echo a b c

# at prompt, press m+. and m+,
# observe that both insert the word 'c', but the latter should insert 'echo'

If you do the above in the reverse order (bindkey commands first, then source), you'll notice that the keybinds work as expected before the source.

Expected behavior

As man zshzle indicates, this wrapper for insert-last-word -- -1 1 should insert the first word of the previous command.

Screenshots

Desktop

  • OS + distribution:
    • macOS ventura
    • arch linux 20230625.0.160368
  • Zsh version: both 5.9
  • Plugin version: current master, bug also present on v0.6.0, v0.5.0, v0.4.0, v0.3.0

Tested with v0.2.0 as well, got:

_zsh_autosuggest_bound_insert-last-word:zle:2: unknown option: 1

Additional context

I'm quite confused how this used to work in my config and doesn't anymore. I haven't updated plugins recently, but apparently I must have changed something seemingly unrelated in my config. Will keep looking, but not sure I'll be able to track down what the issue is myself.

I also tried unset ZSH_AUTOSUGGEST_USE_ASYNC and export ZSH_AUTOSUGGEST_MANUAL_REBIND=1 (after sourcing the plugin), but neither of those seemed to make a difference.

@Amar1729 Amar1729 added the bug label Jul 2, 2023
@Amar1729
Copy link
Author

Amar1729 commented Jul 2, 2023

Slight addendum: as the SO post notes, the same behavior can be achieved built-in by alt+0 alt+. and indeed, bindkey -s '^[,' '\e0\e.' does properly insert the first word from the previous command while the plugin is sourced. So while this particular issue has a solution, I'm not sure if this indicates some deeper bug that could mess up something else.

@huyz
Copy link

huyz commented Apr 3, 2024

Thanks, this saved me time to figure out what was wrong with my shell.

Disabling autosuggestions worked for me.

My best guess is that something changed with zsh 5.9. This issue seems to have started happening with zsh 5.9, which is the default version of the latest macOS 14.4.1 (Sonoma) and is the latest version installed by Homebrew. In contrast, the latest one for Ubuntu 22.04 is zsh 5.8.1, which may be why we haven't seen many people complain yet. And with zsh 5.8, there's no issue.

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

No branches or pull requests

2 participants