Stuck in Tmux Scroll Up? Try These Methods

Tmux (name derived from Terminal multiplexer) is one of the best open-source terminal/shell multiplexers for Unix-based operating systems (e.g., Linux distros, Mac, etc.). Tmux allows simultaneous access to multiple terminal sessions in a single window. It is quite useful in running more than one command-line script/program at the same time.

Tmux Scroll Up

But due to its multiple windows operating at the same time, for some of the users, it becomes difficult to scroll up in the terminal windows (either from the keyboard or mouse). And the issue aggravates due to the multiplicity of the Unix-based OSs.

But no need to worry, a user can scroll up easily in Tmux as discussed below:

Enable and Use the Scroll Mode of Tmux

You can scroll up and down in Tmux by using the following:

  1. Press Ctrl + B keys followed by the [ key.
    Press Ctrl + B + [ Keys to Enable Scroll Mode of the Tmux
  2. Now use the normal navigation keys on the keyboard like up arrow/down arrow, page up, page down, etc. to navigate the Tmux interface.

When a user is done with scrolling, he can get out of scroll mode in Tmux by pressing the Q key. If that did not work as per the expectations, then check if using the F7 key to enter the scroll mode and q to quit the mode solves the problem.

Enable and Use the Copy Mode

  1. Press Ctrl + B keys followed by PgUp key.
  2. Now the terminal will go one page up directly in Tmux and check if this satisfies your requirements.

Use the VI Mode

If Tmux is controlled by an attached client, then it is called a VI mode in Tmux. In the VI mode, you may use Shift + K and Shift + J keys to navigate line by line in the Tmux interface (if in the scroll mode), otherwise, the only cursor will move when the mentioned keys are pressed. Also, you may press the C-B  keys (twice) to scroll up a page and the C-F keys to scroll down a page in the Tmux.

Edit the Tmux.Config File

For some of the advanced users, the above methods might not be satisfactory, in that case, editing the Tmux.config file might solve the problem (as discussed below).  You may launch the Tmux.config file by executing vim ~/.tmux.config in the terminal.

Enable Mouse Scrolling

  1. Add the following lines to the Tmux.config files as per the Tmux version:
    For the Tmux version 2.1 and up 
    set -g mouse on 
    
    For the Tmux version below 2.1 
    set -g mode-mouse on
  2. Now check if the mouse scrolling is working fine.

Keep in mind you may hit the Q key to exit the scroll mode afterward. Also, to copy the contents from the terminal you may use the Shift + Mouse Left Click to perform the copy operation.

Enable Mouse Scrolling with Key Binding:

  1. Add the following lines to the Config file:
    set -g mouse on
    
    # sane scrolling:
    
    bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e; send-keys -M'"
  2. Now, end the Tmux processes by executing the following:
    tmux kill-server && tmux
  3. Then launch Tmux and check if its scrolling is working as per your expectations.

Keep in mind that if you have to copy an item in the Tmux’s mouse mode, then use the Shift key + left mouse click to copy the contents.

If that did not work, check if adding the following to Tmux.config solves the problem:

set -g mouse on

bind -n WheelUpPane {

    if -F '#{==:#{window_name},nvim}' {

        send-keys -M

    } {

        copy-mode -e

    }

}

Enable Default Xterm Scrolling

  1. Add the following lines to the Tmux.config file:
    # Sane scrolling
    
    set -g terminal-overrides 'xterm*:smcup@:rmcup@'
  2. Now check if the Tmux scroll is up to your expectation.

If that did not work, check if adding the following to the configuration file of Tmux adds the required behavior (but you may have to reboot your system afterward):

# Allow xterm titles in the terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right

set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"

But keep in mind if you change the terminal type to Putty, then the above code may not work and if you have to use Putty, then you may add the following to the configuration file of Tmux:

set -g terminal-overrides "putty*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"

If that did not work, you check if adding the following to the configuration file solves the problem:

set -ga terminal-overrides ',xterm*:smcup@:rmcup@'

For macOS Mojave and Above

Just use Option + UpArrow to scroll up and Option + DownArrow to scroll down on a Mac with macOS X and above.

Use Option and Navigation Keys to Scroll in Tmux

If that is not working, enter the copy mode by pressing the following:

ctrl + b + [

Then to scroll up or down a line by using the up or down arrow keys. To scroll a page up or down, you may use the fn + up arrow or fn + down arrow key. And whenever you have to quit the mode, just press the q key.

Try a Plug-in

If none of the above worked as per your expectation, then using a plug-in like Tmux-Better-Mouse-Mode may fulfill your requirements.

Download Tmux Better Mouse Mode Plug-in
ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.