Bash – reverse of yank-last-arg/insert-last-argument

bashcommand history

yank-last-arg / insert-last-argument is probably better known by its usual shortcut, Alt.. It's very nice to navigate through the last argument of earlier commands, but if you're navigating a little too fast it's easy to miss the argument you wanted, and then it seems you have no other choice but to start all over again. This slows down the navigation, so I hope there's a command to navigate this list in reverse.

A quick look at bind -P didn't show any obvious candidates for this purpose.

Best Answer

If you type Alt-- 1, then Alt-. the direction is reversed. Typing it again revert back to the usual direction.

Some explanations are in bash's man page:

       yank-last-arg (M-., M-_)
              Insert  the last argument to the previous command (the last word
              of the previous history entry).  With a numeric argument, behave
              exactly  like  yank-nth-arg.   Successive calls to yank-last-arg
              move back through the history list, inserting the last word  (or
              the  word  specified  by the argument to the first call) of each
              line in turn.  Any numeric argument supplied to these successive
              calls  determines  the direction to move through the history.  A
              negative argument switches the  direction  through  the  history
              (back or forward).  The history expansion facilities are used to
              extract the last argument, as if the "!$" history expansion  had
              been specified.