A window takes the entire screen of the terminal and it is within the sessions. A session can have multiple windows but can only display one at a time. A window can be divided into multiple panes with which we will work.
A pane is the part of the window in which the terminal we are working with is located. Here, there is no more mystery.
It is as easy as if you are working on Linux:$ apt-get install -y tmux
And if you are on Mac:$ brew install tmux
To start tmux just execute $ tmux on the terminal. This will launch a session of tmux with a name that will be put by the tmux itself. If we want to create a session with a name that suits us more, we would have to launch $ tmux new -s mySession.
With this, what we just did is that we opened a terminal with a bar below with something similar to this:
Here, it is informing us that we are in the session mySession and that we have a single window that has the name of the command that is being executed at the moment.
Before proceeding with the practical part you have to understand what the prefix is. The prefix is nothing more than a sequence of keys that press previous to any command of tmux. By default, it is Ctrl – b, on the internet they symbolize it as C-b. Just for your information, I would like to add that you have to press control and without releasing it, press b, it can then be released to launch the command of tmux.
C-b + s – List of sessions in our tmux server
C-b + $ – Rename session
C-b + d – Detach current session (not about deleting it, just leaving it in the background). We go to the terminal and it will show us a message similar to [detached (from session mySession)].
Once outside the session, we can launch $ tmux ls to see the list of active sessions and attach again with $ tmux attach -t <name of the session>, eg:
If we want to create a new window within our session, we should press C-b + c, this would leave us the bar below like this:
To be able to move between windows, there are several commands, I will explain the most used ones:
Prefix + p – Go to the previous window
Prefix + n – Go to the next window
Prefix + [number] – Go to a specific window (the number is shown right next to the window)
Prefix + & – Close the window (needs a confirmation)
Once we have it clear on how to move through the different windows, we are going to divide these windows into different panes:
Prefix +% – Divide it vertically
Prefix + “ – Divide it horizontally
It’s actually quite easy, doing several tests, we could get something like this:
Now, what is left is to move between panes and several actions that are very common with the panes.
Prefix + [arrows] – Move between panes in the direction of the arrow
Prefix + x – Close pane
Prefix + z – Zoom to the active pane (Prefix + z again to zoom out)
Prefix + or – Next pane
Prefix + spacebar – Change the layout of the current panes
Prefix +! – Convert pane to window
Obviously, this is something fairly basic with which you will improve productivity. Based on my experience, if you have just started, I would recommend you to do these commands, that you force yourself to always use tmux and once you feel comfortable, try to discover the wonderful world of making your own tmux configuration, install plugins and even map keys (for example, my prefix is C-a instead of C-b, something quite common in the tmux community).
ctrl+b
(my modified prefix is ctrl+a) and then: