23

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?

3 Answers 3

32

Run this command:

$ tput rmcup

What happened most likely is that you were, either locally or remotely, running a command (like vim, or 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?

7
  • No I'm just using the default terminal app. Running that command did not fix my problem and it didn't give me any output.
    – Victor Cui
    Apr 10, 2019 at 20:07
  • 1
    This worked for me macOS Catilina over ssh to debian server
    – styks
    Mar 2, 2020 at 21:03
  • 1
    My ssh connection broke while I was viewing a document in vi. This happened and your solution worked.
    – ChristineB
    Apr 22, 2020 at 14:24
  • I'm glad to hear this was helpful for you!
    – DopeGhoti
    Apr 22, 2020 at 22:00
  • 3
    Somehow I ran into the same issue in bash, doing curses development on linux, so it's not just tmux or mac. This command fix it, thanks.
    – Alcamtar
    Nov 15, 2020 at 3:21
5

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.

0
2

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.

The 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. :)

1
  • Thanks, that helped me. It works on Raspbian buster, but when the mouse is on, it is no longer possible to select text. Note that I don’t observe the auto-copied text and pane draping behaviors you mention.
    – nico
    Nov 28, 2021 at 15:35

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.