50

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?

1
  • 2
    This is annoying to me too. Commented Aug 13, 2022 at 5:19

3 Answers 3

65

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?

9
  • 2
    This worked for me macOS Catilina over ssh to debian server
    – styks
    Commented Mar 2, 2020 at 21:03
  • 2
    My ssh connection broke while I was viewing a document in vi. This happened and your solution worked.
    – Cebbie
    Commented Apr 22, 2020 at 14:24
  • 4
    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
    Commented Nov 15, 2020 at 3:21
  • 2
    I had a similar issue due to a pager ungracefully exiting. I solved it by opening a man page man tput and then closing it. It seems like opening any other program that uses the alternate screen mode (man, less, vi, vim, ect.) and then closing it normally is another potential fix.
    – Cole
    Commented Aug 4, 2022 at 1:11
  • 6
    Didn't work for me (iterm). Commented Aug 13, 2022 at 5:21
8

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.

1
  • Didn't work for me (iTerm). Commented Aug 13, 2022 at 5:20
6

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

4
  • 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
    Commented Nov 28, 2021 at 15:35
  • 1
    Didn't work for me (iTerm). Commented Aug 13, 2022 at 5:20
  • 1
    @SridharSarnobat check this out. stackoverflow.com/a/70393585/2190689
    – ssi-anik
    Commented Nov 22, 2023 at 11:29
  • If you have another command running and you have scrolled up, to quickly jump to the bottom, press enter. If you have a command running and not asking for any input should take it back to the bottom.
    – ssi-anik
    Commented Nov 23, 2023 at 2:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .