16

In Bash, you can press Alt-. to insert the last argument of the previous command. If you press it multiple times, it cycles through the last arguments of all of the commands in your history. However, sometimes I press it too many times, and I want to reverse the direction of the cycling, hence go forwards. Is this possible?

(i.e. if you reverse-i-search with Ctrl-r, you can change directions with Ctrl-s. What is the analogue for Alt-.?)

1 Answer 1

17

If you supply a negative argument to Alt-., it reverses direction. The easiest way to do that (with standard keybindings) is Alt-- (equivalent to an argument of -1).

So, after one or more Alt-. keypresses, pressing Alt-- will cause the next Alt-. to go in the reverse direction. (Just ignore the argument dialog which appears when you press Alt--.)

6
  • 1
    I'm not sure what you mean exactly. Pressing Alt+- removes the command-line prompt and inserts (arg: -1) instead. The command itself is unchanged.
    – Sparhawk
    Commented May 12, 2013 at 6:23
  • 1
    Thenext alt-. (with the -1 arg) will go forwards.
    – rici
    Commented May 12, 2013 at 6:46
  • That's great! I've edited the answer to make it a bit clearer. What does alt+- do exactly?
    – Sparhawk
    Commented May 12, 2013 at 12:35
  • 2
    @Sparhawk: as I said, alt - produces an argument of -1 for the next readline command. Or, more precisely, it starts a negative argument, so alt -, alt` 2 would produce an argument of -2. In the case of alt ., only the sign of the argument matters, and only if it is negative, so alt - is sufficient. (The first alt . handles its argument differently. See the bash manual.)
    – rici
    Commented May 12, 2013 at 16:12
  • Thank you. I often find man bash slightly opaque for such situations, but I think it's clarified it a little here.
    – Sparhawk
    Commented May 14, 2013 at 2:22

You must log in to answer this question.

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