Home Terminal Tuts How to navigate through panes in Tmux

How to navigate through panes in Tmux

by Abraham
navigating panes tmux

The quick and adaptable command terminal is one of the most defining aspects that distinguishes Linux distributions from other operating systems. The command terminal enables users to carry out complicated commands with only a few lines. That being said, there may be occasions when a single terminal screen is insufficient for your work. However, there are programs available for free to assist you in overcoming this obstacle.

The ability to move between terminal windows is one of Tmux’s most noticeable features. Switching between Tmux windows and panes will help you handle your commands and shell scripts more effectively. This article will teach you how to browse via various panes in Tmux. Besides, we shall briefly cover this application’s installation and initialization. Therefore, continue reading this article guide to learn more about this subject matter.

Installing Tmux

It is vital to install Tmux on your Linux operating system before proceeding to any other step. If you want to check if Tmux is installed on your system, execute the following line of code:

tmux -V
check tmux version

Check Tmux version

If it returns a version number as illustrated in the snapshot above, then Tmux is installed in your system. However, if you encounter a ‘Command not found’ error, Tmux is not installed. Therefore, you need to install it using this line of code:

sudo apt install tmux

Launch a Tmux session

Once Tmux is installed, the next step is to start a Tmux session. This can be done using the following command:

tmux
tmux new screen

Tmux new screen

Now that Tmux is up and running, please proceed to our primary subject matter, learning how to navigate through panes in Tmux.

Tmux Panes

A tmux pane is an item we utilize to perform commands, scripts, and processes like ssh, backup, vim, htop, etc. They are technically pseudoterminals that encapsulate shells, similar to Zsh or Bash. They are, in other words, terminals within terminals. Panes manage the user’s workflow by separating the Tmux window into horizontal and vertical panes, each of which runs a process or a program. The arrangement of the panes is controlled by the tmux window in which they are shown. When the tmux server is started, a session is created by default. A single window is established inside this session. By default, this window will only have one pane.

Panes are formed by separating the window in which they reside. Splitting may be done vertically or horizontally with Tmux shortcuts or commands (good when scripting). A Tmux window can often have numerous panes open. The terminal dimension determines how many panes can be divided further.

Below are essential commands that can be used to split panes:

  1. Default Prefix = Ctrl + b
  2. Default Prefix + % or split-window -h – This command splits the window into two horizontal panes
    split window horizontally

    Split window horizontally

  3. Default Prefix + ” or split-window -v – This command splits the window into two vertical panes
    split windows vertically

    Split windows vertically

Note: When you press Prefix + w, Tmux displays a list of windows and their related panes. In the illustration below, we can note that there is just one window open in the current session. The window is called “1,” and it has two panes. The pane with the name “tmux” is the active pane in Window 1. Tmux, by default, assigns the executing process’s name to the pane.

display a list of active windows

Display a list of active windows

As previously said, tmux is a program that allows its user to run and manage many terminal sessions simultaneously. This part will teach you how to build and manage tmux panes and Windows. Tmux employs keyboard shortcuts, often known as prefixes. These are keyboard input combinations that are used to classify various sorts of functions.

Ctrl + B” is the Prefix in charge of pane and Window management. Almost all pane management commands begin with this Prefix. To launch a new window using the default prefix preceded by c.

To navigate panes and windows, you need to get acquainted with the following commands:

  1. Default Prefix + w = Enables you to select from a provided list of open windows
    display a list of active windows

    Display a list of active windows

  2. Default Prefix + 0 = Allows you to switch between open windows. 0, in this case, represents the number of the window you want to change to.
    shift to different window

    Shift to a different window

  3. Default Prefix + type = Allows you to rename a window
    rename a window

    Rename a window

The commands provided above are tailored specifically for individual windows. However, there are instances where you will need more terminal sessions in the same window. This can only be achieved using panes.

We can use two methods to split the Tmux window into separate panes. As stated earlier in this guide, one technique allows you to do horizontal splits, while the other will enable you to do vertical splits.

  1. Default Prefix + % or split-window -h – This command splits the window into two horizontal panes
    split window horizontally

    Split window horizontally

  2. Default Prefix + ” or split-window -v – This command splits the window into two vertical panes
    split windows vertically

    Split windows vertically

Navigating panes

Navigating panes is relatively straightforward. You can do so by utilizing the following commands:

  1. Default Prefix + 0 – This command will aid users in switching to the next pane
    shift to different window

    Shift to a different window

  2. Default Prefix + ;  – This command will help users alternate between panes
    shift between panes

    Shift between panes

    Note: If you see the previous screenshot, it is in ‘bash,’ but after executing the switch command, it moves to the ‘tmux’ pane

  3. Default Prefix + x – This command permits users to quit the active pane. When you are sure you want to leave that pane, click ‘y’ in the highlighted section below. (Alternatively, you can also type exit on an active pane to quit it)
    kill active pane

    Kill active pane

You can also do pane management by executing the following commands on your Tmux terminal window:

swap-pane -D

swap-pane -U

The swap-pane – D command allows users to navigate the panes in a clockwise direction. On the other hand, the swap-pane -U command permits users to navigate through the panes in an anti-clockwise direction.

The following Tmux pane shortcuts can come in hand for you if you use it regularly:

  1. Default Prefix + ” – Split windows vertically
  2. Default Prefix + % – Split windows horizontally
  3. Default Prefix + { – Move the current pane to the left
  4. Default Prefix + } – Move the current pane to the right
  5. Default Prefix + q – Show pane numbers
  6. Default Prefix + z – Toggle the pane zoom option
  7. Default Prefix + (↑ ↓ ← →) – Change panes to the direction highlighted
  8. Default Prefix + Ctrl + (↑ ↓) – Resize the height of the current pane (To perform the resize, hold onto the Ctrl key while tapping the down or up keys)
  9. Default Prefix + Ctrl + (← →) – Resize the width of the current pane (To perform the resize, hold onto the Ctrl key while tapping the right or left keys)
  10. Default Prefix + ! – Convert a pane into a window
  11. Default Prefix + 0 … 9 – Select/Switch the pane by number
  12. Default Prefix + spacebar – Toggle between different pane layouts
  13. Default Prefix + o – Switch to the next pane
  14. Default Prefix + x – Close the current pane

Conclusion

This article guide has comprehensively covered how to navigate through panes in Tmux. Learning to navigate through panes in Tmux makes it relatively easier to manage sessions. I hope this guide helped you out. If yes, please leave a comment in the message board below.

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.