6

I know about Alt + . to show the previous argument in bash.

But what if I went past the desired argument (pressing Alt + . one too many times) and I want to go forward in history?

Is there a key combination for that?

2
  • 1
    Other than just up and down arrow key's? I mean, that may or may not sound obvious to you, but I just want to be sure.
    – Gravy
    Jun 30, 2016 at 20:18
  • 2
    @Gravy Argument, not command. M-. and M-_ are bound to the yank-last-arg readline command. There's a yank-nth-arg on M-C-y, but I'm a vi user so I'm not familiar with Emacs key mappings. Heck I don't even have a Meta-key...
    – Kusalananda
    Jun 30, 2016 at 20:22

1 Answer 1

5

The Alt-. runs readline function yank-last-arg:

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 word, as if the "!$" history expansion had been specified.

So to reverse its meaning one has to supply a negative argument to it. This can be done via other functions: digit-argument or universal-argument. The first is easier to use because it is already bound to Alt-[[:digit:]] and Alt-- for negative arguments.

So, to go backward in history run Alt-.. To go forward run Alt-- Alt-. and repeat with just Alt-.. To go backward again, switch directions again with Alt-- Alt-..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .