3

In zsh, I have alt+. bound to insert-last-word

When I am listing through the last command parameters by repeatedly pressing alt+., sometimes I press one too many and I need to go one back.

What keybinding is used to go back?

3

You can just undo, bound to Ctrl+_ in emacs mode by default (note that insert-last-word is also bound to Alt+_).

After undoing though, if you invoke insert-last-word again, you'll be back to the beginning, you can't just alternate pressing Ctrl+_ and Alt+_ to go back and forth in the history.

For that, you'd need to define a separate widget that invokes the insert-last-word widget with 1 as argument (see info zsh insert-last-word for details).

For instance, bound to Alt+,:

insert-last-word-forward() zle insert-last-word 1
zle -N insert-last-word-forward
bindkey '\e,' insert-last-word-forward
  • the bind on the last line did not work. I had to change that to bindkey. – Martin Vegter Nov 14 '18 at 21:07
  • @Martin, sorry, my bad. Fixed now. – Stéphane Chazelas Nov 14 '18 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.