Home Terminal Tuts How to use Tmux mouse mode

How to use Tmux mouse mode

by Abraham
tmux mouse mode

Tmux is an open-source multiplexing tool used to handle multiple terminal windows efficiently. If you have used the terminator application previously, you should be familiar with this app. With the aid of Tmux, users can split the terminal into several panes, adjust the pane size, move the panes around, and switch between them. This application aids in reducing the pain of managing multiple tabs and windows of the Gnome terminal.

Tmux is a popular multiplexer; thus, it has plenty of valuable options. It allows users to run programs in parallel while permitting a seamless transition. If you continuously switch between terminals, you could consider trying a multiplexer.

All corresponding remote sessions are closed when you close an SSH connection. However, Tmux comes in handy as it aids preserve those sessions even if the SSH connection is terminated.

This article guide will only brush through the installation, how to use and how to launch section. If you want to learn more about the said sections, check out this in-depth article guide.

How to install Tmux on Linux

Before you initiate the installation phase, you should have the following prerequisites at your disposal:

  1. Linux/Unix-based OS
  2. Command-line access
  3. Root /Sudo user account

Once you have assembled all the prerequisites, launch your terminal using the Ctrl + Alt + T keyboard combination and execute the following line of code:

sudo apt install tmux
install tmux

Install Tmux

Alternatively, you can employ the Ubuntu Software Center to install it. Launch Ubuntu Software Center via the applications menu, search for ‘tmux’ and click ‘Install’ to install it on your Linux OS.

install tmux via software center

Install Tmux via the software center

How to Launch Tmux

Once Tmux has been installed, we will have to use the Gnome terminal to invoke it since Tmux does not ship with an application or icon associated with it. To launch it, open the terminal and execute the following line of code:

tmux
tmux new screen

Tmux new screen

Note: If you are opening Tmux for the first time, you might encounter the error shown below:

"open terminal failed: missing or unsuitable terminal: xterm-256color"

If you are a victim of this fault, don’t worry; I will illustrate how to fix it. First, fire up your terminal and execute the following line of code to fix the error:

export TERM=xterm

When you re-run this command, the error will be solved. If this method doesn’t work for you, use the ‘XTERM’ terminal to launch tmux.

How to use Tmux

Tmux uses notions like sessions, windows, panes, and hotkeys. As a result, newcomers typically find it intimidating at first. However, you’ll feel much more productive after you’ve mastered it. A Tmux session denotes the scope of the job at hand. Windows allows users to do a range of tasks inside a single session, while panes will enable you to deal with many viewpoints in a single window. Tmux hotkeys consist of the Tmux prefix (Ctrl + b) followed by a key. These commands are used to control activities conducted in the Tmux. The default prefix is “Ctrl + B.”

How to use Tmux mouse mode for Tmux version 2.1 and above

How nice would it feel to find out that you can use your mouse to scroll and select content in your Tmux window? I guess you would feel nice. If that is the case, don’t wonder anymore, as I will illustrate how to do that in this section. In Tmux, we can enable the mouse mode by customizing the tmux.conf file.

First, to use the mouse mode in Tmux, we must enable it. You can do so by opening the tmux.conf file by running the following line of code:

sudo nano ~/.tmux.conf
start tmux.conf file

Start tmux.conf file

Once the tmux.conf file has been launched, append the following lines:

setw -g mouse on
append the setw mouse mode

append the setw mouse mode

Click ‘Ctrl + x’ on your terminal to exit the file and ‘y’ to save it.

Now reload the tmux.conf file by using this line of code:

tmux source-file ~/.tmux.conf
reload tmux config file

Reload the Tmux config file

Note: It is always essential to reload the tmux.conf file to effect the changes made.

Now that we have reloaded the Tmux file, we can use our mouse to control pane resizing, window selection, and pane selection.

How to use Tmux mouse mode for Tmux version 2.1 and below

Similarly to what we did in Tmux version 2.1 and above, we shall be doing so in this section too. We shall customize our tmux.conf file to enable mouse mode. Open your tmux.conf file using the following command:

sudo nano ~/.tmux.conf
start tmux.conf file

Start tmux.conf file

Once the tmux.conf file has been opened, append the following lines of code:

setw -g mode-mouse on

set -g mouse-select-pane on

set -g mouse-resize-pane on

set -g mouse-select-window on
append the following lines of code

Append the following lines

Save and exit the nano file editor using the (Ctrl + X) followed by ‘y’ key combinations.

Reload the tmux.conf file by executing the following line of code:

tmux source-file ~/.tmux.conf
reload tmux config file

Reload Tmux config file

Mouse mode should now work flawlessly for your Tmux below version 2.1

How to use the mouse to select in Tmux

We can now use our mouse to select words or content in our Tmux terminal. For instance, to select a word, hold the right mouse button and double-click on the left mouse button. Similarly, to select a line, hold the right mouse button and triple-click the left mouse button.

select using mouse

Select using mouse

Note: You can also use the ‘Arrow’ keys to select multiple lines.

Considering that if you want to use the Tmux keybindings comfortably, you will need to disable the mouse options by toggling the set-mouse mode on to off. Alternatively, you can open your tmux.conf file and append the following line:

setw -g mode-mouse off
turn off mouse mode

Turn off the mouse mode

By setting the mouse mode to off, you would have saved yourself the embarrassment of selecting Tmux’s panes and windows using the mouse mode.

That’s all. You have successfully enabled the mouse mode on your Tmux terminal.

Conclusion

We have briefly covered installing, launching, and using Tmux on our Linux machine. Even though we brushed through those sections, we could still cover the most critical aspects that can be implemented to get you going using Tmux. The main agenda of this article was to cover how to use the Tmux mouse mode, and we have explained in detail how to enable and use the mouse mode. Although Tmux mouse mode is available, it is often preferable to utilize the Keyboard. As the number of apps rises, using a mouse to flip between panes and windows running various applications becomes quite distracting.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.