Recently I started using tmux inside my terminal on my Mac. However now whenever I'm in a tmux session and I scroll up or down using my mouse, it scrolls through my command history instead of scrolling through my terminal pane. How do I disable this feature and make mouse scrolling go back to the default behavior?
Run this command:
$ tput rmcup
What happened most likely is that you were, either locally or remotely, running a command (like
top, or many programs that use libraries similar to
ncurses) that uses the terminal's "alternate screen" mode. When this is active, many terminal programs helpfully remap the scrolling action on the mouse to arrow keys, because generally scrolling the local display is less than helpful. If this application terminated ungracefully, your terminal may still think it's in that mode.
This command resets this, and should re-enable your ability to scroll.
I'm guessing you're using iTerm?
The reason for this is probably that your terminal sends Up and Down keys for the mouse wheel when applications are in "cursor positioning mode" but do not request the mouse themselves, which is the case for tmux with the mouse option off.
You can perhaps configure your terminal not to do this, but it is unlikely. However, most terminals allow you to hold Shift or Ctrl or some other modifier key to select or scroll anyway so you could try this.
You will find when running tmux that the terminal scrollback is not reliable because tmux has little control over it. The recommended way to copy text when using tmux is to turn on tmux's own mouse support (set -g mouse on) and use copy mode.
As mentioned by @Nicholas Marriott in a comment, a
set-option -g mouse on line in your
.tmux.conf will probablly do what you want. (Make sure you're using the latest tmux version.) This sets a global option that turns on mouse interactivity.
mouse option will also have tmux automatically copy text when you select it, and you'll be able to click on tmux panes and drag their borders.
This might also have a few side effects, so you can of course decide whether you want to go this route:
The scrolling in tmux is a little different from normal terminal emulator scrolling. E.g., I'm not sure how to get the nice "scroll to bottom on input" behavior, but it seems that if you need to you can substitute a quick
^C to get back to the bottom. (This simply goes to the bottom if you have scrolled up, and doesn't print another command prompt.)
The biggest downside is (AFAIK) you won't be able to scroll inside a pager program. (You might be able to hack around this somehow, though.)
You might not need an answer to this question now, judging by the original post date, but hopefully this helps someone. :)