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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The Alt-. runs readline function
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:
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-..