M. Lanza
M. Lanza

Reputation: 6790

Maintain position in terminal command history on macOS?

I enter many commands into the terminal. I enter command a, then b, then c, etc. I'm on command g now but I want to execute a, then b, then c, again.

I press up (g), up (f), up (e), up (d), up (c), up (b), up (a), then enter to execute a. I have to press up 7 times again to get to and execute b. Same for c.

On Windows, I maintain my position in the command history. So once I get to command a and press enter, I just press up maybe twice to get to b, and maybe twice again to get to c. This makes repeating sequences easier, obviously. The terminal apparently stays at its HEAD position, relative to history.

How can the macOS terminal be reconfigured to maintain its position in the command history?

Upvotes: 0

Views: 49

Answers (2)

Chris N
Chris N

Reputation: 949

History search is controlled by the shell, and has nothing to do with the terminal emulator or the OS, beyond what’s installed by default.

If you like what your Windows system is doing, check the shell there (echo $0), its version, and history-related settings in the config files, and use the same setup on your Mac.

You don’t actually say what shell you’re using, but zsh can be configured to do pretty much anything.

Upvotes: 0

chepner
chepner

Reputation: 532093

The up-arrow can be preceded by a count to indicate how many commands back you want to go. How you do that depends on whether you use emacs or vi bindings, but I'll assume you are using the default emacs bindings.

To go back 7 commands, press Escape, then 7, then . If you wanted to go back 10 or more times, press Escape before each digit in the count. (For example, to go back 13 commands, press Escape 1 Escape 3 .)

Upvotes: 2

Related Questions