ESC-.
(insert-last-word
) considers any space-separated or space-separable shell token¹ a “word“, including punctuation tokens such as &
.
You can give it a numeric argument to grab a word other than the last one. Positive arguments count from the right: Alt+1 Alt+. is equivalent to Alt+., Alt+2 Alt+. grabs the previous word, etc. Alt+0 Alt+. is the previous word, and negative arguments continue from the left, e.g. Alt+- Alt+1 Alt+. is the first argument.
I have copy-earlier-word
bound to ESC-,
. Where repeated invocations of ESC-.
insert the last word of successive commands going back in the history, repeated invocations of ESC-,
after ESC-.
insert the previous word of the same command. So with the following code in your .zshrc
, you can get the next-to-last word of the previous command with Alt+. Alt+,.
autoload -U copy-earlier-word
zle -N copy-earlier-word
bindkey '^[,' copy-earlier-word
¹ There are several reasonable definitions of “token” in this context. In this answer I'm going by the definition “something that insert-last-word
considers to be a separate word”.
bash
? – Kusalananda Dec 24 '18 at 19:26echo $SHELL; echo $TERM;
– Timothy Pulliam Dec 24 '18 at 20:01