When it comes to CLIs, no operating system can compare itself to Linux. Each Linux distribution is heavily integrated with its terminal, allowing one to execute complex processes with just a few commands.
While the terminal may be self-sufficient on its own, having some extra features just adds to the experience. One such useful feature would be the ability to manage multiple terminal windows and sessions at once. Fortunately, there exists a program that can suit your needs.
tmux allows its users to have more than one session of the command terminal open at a single instance. It allows them to create, manage, and navigate through multiple terminal windows at the same time.
With a plethora of features, technical and visual customizability, and easy-to-understand documentation, it can definitely be said that tmux is a must-have to boost your CLI experience.
Copy Mode in tmux
tmux comes with a variety of modes that make working and managing multiple sessions easier. One of these modes is “copy mode”. As the name suggests, copy mode allows one to copy a certain block of text and paste it into another location.
If you’re coming from using GUI-based applications like Word and Notepad, which make use of mouse selection methods to copy text, copying in tmux may seem difficult as the process is purely keyboard-based.
No need to worry, as this guide will help you learn how to use copy mode in tmux. We will go over the basics along with some navigation tips to help you familiarize yourself with copy mode.
Enable Copy Mode in tmux
Let us start by learning how to enable copy mode in tmux. This method makes use of the command terminal.
We’ll be using Ubuntu 20.04 for this tutorial. However, the method is the same for other Linux distributions.
To start a tmux session, begin by opening the command terminal.
Once the terminal opens, open a new tmux session by using the following command:
Next, try to access the tmux.conf file using the text editor of your choice. For this, make sure that you’re in your default home directory. You can find your directory location with the help of the following command:
The output will display the current directory. In case you’re not in the directory of your choice, use the $cd command to change the directory as follows:
Once you’re done with this, open the tmux.conf file in a text editor. For this tutorial, we’ll be using nano.
This should open the configuration file.
Once the configuration file opens, add the following line to enable copy mode:
Once that’s done, save the file. You should now have access to copy mode.
To test it out, start a tmux session and open some panes. This should be possible by using the following shortcuts.
- Split the tmux window into two vertical panes, press Ctrl + B and type %
- Split the tmux window into two horizontal panes, press Ctrl + B and type “
Now, you can proceed to enter copy mode on tmux. To do this, simply press Ctrl + [. The change in text cursor should indicate that you are now in copy mode.
Navigating in Copy Mode
Navigation keys in tmux copy mode resemble the ones used in vim. A list of useful navigation keys is given below:
- h, j, k, l directional input corresponding to left, down, up, right
- w or W refers to moving at the front by a word
- e or E refers to moving towards the end
- b or B refer to moving back by a word
- { or } refer to moving a paragraph back or forward
- Ctrl + e refer to scrolling down by a line
- Ctrl + d refer to scrolling down by half of the screen
- Ctrl + f refer to scrolling down to the end of the screen
- Ctrl + y refer to scrolling up by a line
- Ctrl + u refer to scrolling up by half of the screen
- Ctrl + b refer to scrolling down to the start of the screen
- / or ? refer to search by moving forward or backward
- n or N refers to repeating the previous search by moving forward or backward, etc.
To start copying the text, highlight the text by pressing space. Copy the text by pressing Enter. Navigate to the place where you wish to paste the text and press Ctrl + J to paste it.
Conclusion
This was a guide on how you can use copy mode in tmux. We went over the basics of copy mode, how to enable it, and navigate through it. Lastly, we talked about how to use it to copy text.