In a terminal, are there any shortcuts to jump to a previous/next prompt? Scrolling up and trying to find the start of a log slows down my workflow.

I'm using iTerm on OSX, but this should be applicable to any Unix terminals. A solution in Tmux would help as well.

  • If your hostname is in your prompt, you could reverse search to cycle back that way... – jasonwryan Feb 13 '16 at 22:08
  • Pipe to less. – Kusalananda Jul 30 '16 at 10:10

Inside tmux v2.4+ (relevant commit), you can define a binding to jump to the last prompts with acceptable reliability:

bind-key b copy-mode\;\
           send-keys -X start-of-line\;\
           send-keys -X search-backward " "

Where the " " is a non-breaking space and a corresponding change is made to have you shell prompt contain it ($PS1 or $PROMPT_COMMAND in bash).

It may require special care to set it in the shell prompt and the tmux configuration, as it could be changed to regular space during copy-paste operations (see method with vim in the comments).

Alternatively, you can try your favorite alternative unicode space character or anything that occurs rarely in command outputs and that you're ready to accept seeing in your prompt (🍌?).

This could also be a combination of several characters for even less false positives. It's probably better to pick something at the very end of the prompt, though, for easier navigation.


  • 1
    Cutting and pasting would not get the non-breaking space character to work for me, but I was able to get it to work using Vim. In insert mode, use CTRL-k <space><space> to insert the non-breaking space. Then afterwords, in normal mode, the ga command prints the ASCII value of the character under the cursor which can be used to confirm this character is different from other spaces. – robenkleene Dec 5 '18 at 23:58
  • The following tmux bindings will, once you are in copy mode, let you jump backward and forward between prompts with n and p: bind -T copy-mode-vi n send-keys -X search-forward " " and bind -T copy-mode-vi p send-keys -X search-backward " " (" " should contain a non-breaking space) – Von Feb 7 at 23:34

If you use less to view the contents of the log file, you have the ability to scroll back and forth using the Space and b keys (see the less manual). You may also perform searches in the output with / (and ? for backward search).

To view the output from a program in less, simply pipe the output to it:

$ ./myprogram | less

To additionally save the output in a file:

$ ./myprogram | tee myprogram.out | less

If you press F while reading a file that's being written to, less will behave like tail -f. To interrupt this, press Ctrl+c.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.