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
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
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:
- Default Prefix = Ctrl + b
- Default Prefix + % or split-window -h – This command splits the window into two horizontal panes
- Default Prefix + ” or split-window -v – This command splits the window into two vertical panes
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.
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:
- Default Prefix + w = Enables you to select from a provided list of open windows
- 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.
- Default Prefix + type = Allows you to 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.
- Default Prefix + % or split-window -h – This command splits the window into two horizontal panes
- Default Prefix + ” or split-window -v – This command splits the window into two vertical panes
Navigating panes
Navigating panes is relatively straightforward. You can do so by utilizing the following commands:
- Default Prefix + 0 – This command will aid users in switching to the next pane
- Default Prefix + ; – This command will help users alternate 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
- 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)
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:
- Default Prefix + ” – Split windows vertically
- Default Prefix + % – Split windows horizontally
- Default Prefix + { – Move the current pane to the left
- Default Prefix + } – Move the current pane to the right
- Default Prefix + q – Show pane numbers
- Default Prefix + z – Toggle the pane zoom option
- Default Prefix + (↑ ↓ ← →) – Change panes to the direction highlighted
- 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)
- 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)
- Default Prefix + ! – Convert a pane into a window
- Default Prefix + 0 … 9 – Select/Switch the pane by number
- Default Prefix + spacebar – Toggle between different pane layouts
- Default Prefix + o – Switch to the next pane
- 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.