Window

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.

Pane

A pane is the part of the window in which the terminal we are working with is located. Here, there is no more mystery.

Installation

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

Basic Commands for 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.

Useful Commands for the Session

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:


Useful Commands About Windows

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)

Useful Commands About Panes

Tmux Cheat Sheet

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).

Like This Article? Read More From DZone

tmux ,terminal ,productivity ,cli
Published at DZone with permission of Oscar Galindo . See the original article here.
Opinions expressed by DZone contributors are their own.
start new:
start new with session name:
attach:
attach to named:
list sessions:
kill session:
Kill all the tmux sessions:
In tmux, hit the prefix ctrl+b (my modified prefix is ctrl+a) and then:

Sessions

Windows (tabs)

Panes (splits)

Sync Panes

You can do this by switching to the appropriate window, typing your Tmux prefix (commonly Ctrl-B or Ctrl-A) and then a colon to bring up a Tmux command line, and typing:
You can optionally add on or off to specify which state you want; otherwise the option is simply toggled. This option is specific to one window, so it won’t change the way your other sessions or windows operate. When you’re done, toggle it off again by repeating the command. tip source

Resizing Panes

You can also resize panes if you don’t like the layout defaults. I personally rarely need to do this, though it’s handy to know how. Here is the basic syntax to resize panes:

Copy mode:

Pressing PREFIX [ places us in Copy mode. We can then use our movement keys to move our cursor around the screen. By default, the arrow keys work. we set our configuration file to use Vim keys for moving between windows and resizing panes so we wouldn’t have to take our hands off the home row. tmux has a vi mode for working with the buffer as well. To enable it, add this line to .tmux.conf:
With this option set, we can use h, j, k, and l to move around our buffer.
To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isn’t very efficient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buffer.
For example, we can use 'w' to jump to the next word and 'b' to jump back one word. And we can use 'f', followed by any character, to jump to that character on the same line, and 'F' to jump backwards on the line.

Misc

Configurations Options:

Resources:

Notes:

Changelog:

Request an Update:

We Noticed that our Cheatsheet is growing and people are coloberating to add new tips and tricks, so please tweet to me what would you like to add and let's make it better!