I use tmux (with zsh, if that helps). I have a pretty good setup, but often I find myself running a program with a lot of output, and then entering copy mode and reverse searching for the line I typed into the shell to get to the front of the output. I do this in preference to using less due to the color output, and the fact that sometimes I do want to copy some text.

If I'm running a command that I already know will produce a lot of output, I'd like a way to run it and end up in copy mode at the start of the output, without having to type the command twice. This could take the form of either a way to run a command and drop into copy mode before the output, so the screen doesn't scroll, or a way to enter copy mode and immediately reverse search for the last shell history item. From the tmux docs I can see how to bind keys in copy mode, but there's no documentation on the available functions (i.e., could one bind a key to 'search-reverse "foo"').

  • 1
    less -R preserves the coloring, but usually the command producing the output must be forced to color its output when connected to a pipe, e.g. ls --color=yes | less -R
    – mpy
    Mar 18, 2015 at 19:00
  • Didn't know about the -R flag, that helps a bit. I can at least fix my most common use case, which is hg diff output, by enabling the hg pager extension and using less -FRX as the pager command. Thanks! Still curious about a more general solution for tmux though. Mar 18, 2015 at 20:24

1 Answer 1


usually, not always, you can dump the output into a file. For instance, when my automatic backup runs, it dumps the output into a text file for archiving. I do this by utilizing tee. A sample command is:

ls | tee dumpfile

I see the output on screen, and also everything is funneled into dumpfile for later reading. This may or may not work for you, depending on what the program is you're using.

  • Right, but there are two problems with that; the first is that it does nothing about the output scrolling up, and the second is that, like less, it loses the coloring on the output. Mar 18, 2015 at 17:25
  • Forgot about the color loss, my bad. As for not scrolling, I wasn't sure what you were trying to ultimately do, so I thought a file might have helped. I'll leave this answer up as a not-quite-right solution for others with a somewhat similar issue (Unless you prefer me to remove it) Mar 18, 2015 at 18:12
  • Basically, I type 'cat <mylargefile>' and end up with a couple screens of output and a new shell prompt. I then enter copy mode, reverse search for 'cat <mylargefile>' and can then read through from the start. Instead, I want to either a) do <magic>, type 'cat <mylargefile>' and have the output not scroll until I want it to, or b) type 'cat <mylargefile>', hit a custom keybind, and end up in copy mode with the reverse search already performed. Mar 18, 2015 at 18:23
  • @BenedictSinger does piping it into less do what you need? cat file | less. It's not interactive, but you can scroll through the output at leisure if you're visually looking for something Mar 18, 2015 at 19:43

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.