Hey there, Tmux enthusiasts! I’m here to shed some light on how we can effectively manage our workspaces using Tmux. If you’ve used Tmux, you know how handy it can be to split your terminal into multiple panes or windows. But what about when you’re done? How do you terminate these panes and windows when they’ve served their purpose? That’s exactly what we’re going to discuss in this post. Let’s dive in and become a more effective Tmux user!
Tmux is one of the “terminal multiplexer”, it enables a number of terminals (or windows) to be accessed and controlled from a single terminal. It allows you to create a session on a remote box, run applications in that remote session, “detach” from the session, and re-“attach” when desired. It also has advanced features such as multiple windows and split views. Using tmux is recommend when running an interactive CLI program remotely. If you get disconnected from your session, you can re-attach as though nothing happened.
New to Tmux? No problem, the Tmux fundamentals have got you covered. If you’re already on board, let’s set sail!
Let’s consider the default prefix for tmux, which is Ctrl-B
and let’s go over the commands below using the same. In case you want to change the prefix of tmux you can do it as well.
Let’s look at how to terminate a pane and window when you are inside a tmux window and from outside of tmux as well.
Kill a tmux pane
To kill a tmux pane, you have to switch and stay in the active pane which you want to terminate. Then, you can do the following keyboard default shortcut-
Ctrl-B + x
It’s a series of 2 keyboard keysets you will have to press. You have to press Ctrl-B
, then release the keys, then press x
right after that.
OR
You can also run the tmux
command in the command line to kill the pane-
tmux kill-pane -a -t <pane-number>
So, for example, if you want to kill the pane number 2, you can just run the following command –
tmux kill-window -a -t 2
OR
To kill the window that you are currently working in, you can do the following –
Ctrl-B
:
kill-pane -t <pane-number>
<enter-key>
An example where you can kill the window number 2 is as follows-
Ctrl-B
:
kill-pane -t 2
<enter-key>
Here, you will have to use the prefix Ctrl-B
and then :
to enter into a command entering mode. Then you can type kill-pane
into it and press the Enter Key
.
Kill a tmux window
You can kill a tmux window by killing all panes by pressing Ctrl-B + x
several times until all panes are terminated.
You can also kill the window by pressing the following keyboard default shortcut-
Ctrl-B + &
OR
You can also run the tmux
command in the command line to kill the window-
tmux kill-window -t <window-number>
So, for example, if you want to kill the window number 4, you can just run the following command –
tmux kill-window -t 4
OR
You can use the following to kill a specific window-
Ctrl-B
:
kill-window -t <window-number>
<enter-key>
An example where you can kill the window number 4 is as follows-
Ctrl-B
:
kill-window -t 4
<enter-key>
To kill the window that you are currently working in, you can do the following –
Ctrl-B
:
kill-window
<enter-key>
You can also exit from a tmux session, not just window or pane.
Here, you will have to use the prefix Ctrl-B
and then :
to enter into a command entering mode. Then you can type kill-window
into it and press the Enter Key
.
I hope this tutorial for killing panes and windows in tmux was useful. And that’s a wrap, folks! You’re now well-equipped with the knowledge to terminate panes and windows in Tmux. Cleaning up after a productive session is just as important as setting up, and with this newfound knowledge, you can ensure your terminal stays uncluttered. Keep practicing these commands until they become second nature. As always, stay tuned for more Tmux tips and tricks. Happy coding!
You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.