Learning tmux as a beginner
Tags: shell, tools
Published: 2022-05-03 03:09:53

---
title: Learning tmux as a beginner
published: true
date: 2022-04-30 00:00:00 UTC
tags: Shell,Tools
canonical_url: https://pitayan.com/posts/learning-tmux-as-a-beginner
---

<p>Originally published on <a href="https://pitayan.com/posts/learning-tmux-as-a-beginner">Pitayan | Learning tmux as a beginner</a></p>

<hr />

Nowadays, Tmux has become into the everyday tool in my workdays. I always wanted to summarize the Tmux usage from long ago when I began to use it. So this article is pretty much what I have started with as a Tmux beginner.

## [#](#table-of-contents)Table of Contents

- [What consists of Tmux](#what-consists-of-tmux)
- [What is a Tmux session](#what-is-a-tmux-session)
  - [1. Create a session](#1-create-a-session)
  - [2. Kill a session](#2-kill-a-session)
  - [3. Kill all of the sessions](#3-kill-all-of-the-sessions)
  - [4. Switch between sessions](#4-switch-between-sessions)
  - [5. Rename session](#5-rename-session)
- [What is a Tmux window](#what-is-a-tmux-window)
  - [1. Create a new window](#1-create-a-new-window)
  - [2. Switch between windows](#2-switch-between-windows)
  - [3. Search the windows](#3-search-the-windows)
  - [4. List all of the windows in this session](#4-list-all-of-the-windows-in-this-session)
  - [5. Rename current window](#5-rename-current-window)
  - [6. Close current window](#6-close-current-window)
- [What is a Tmux Pane?](#what-is-a-tmux-pane)
  - [1. Split pane vertically / horizontally](#1-split-pane-vertically--horizontally)
  - [2. Kill a pane](#2-kill-a-pane)
  - [3. Switch between panes](#3-switch-between-panes)
  - [4. Move the current pane to a new window](#4-move-the-current-pane-to-a-new-window)

## [#](#what-consists-of-tmux)What consists of Tmux?

- Session
- Window
- Pane

## [#](#what-is-a-tmux-session)What is a Tmux session?

The "dialog" that's been kept by Tmux for running tasks which can be resumed later disconnection.

### [#](#1-create-a-session)1. Create a session

Creating a session in Tmux is very semantic:

```
$ tmux new -s <session_name>

# e.g.
$ tmux new -s helloworld
$ tmux new -s great
```

### [#](#2-kill-a-session)2. Kill a session

The **`-t`** flag here means "target". Put the target session name after it to delete the session from Tmux

```
$ tmux kill-session -t <session_name>

# e.g.
$ tmux kill-session -t helloworld
```

### [#](#3-kill-all-of-the-sessions)3. Kill all of the sessions

The command `kill-server` seems a bit confusing. But Tmux does have a server running behind the scenes to be able to keep the located processes when the session is detached. So, killing a Tmux server means deleting all saved sessions.

```
$ tmux kill-server
```

### [#](#4-switch-between-sessions)4. Switch between sessions

It's useful when we are in a particular session but want to transfer to another session we used.

```
$ tmux switch -t <session_name>

# e.g.
$ tmux switch -t great
```

### [#](#5-rename-session)5. Rename session

Edit the session name after we created it.

```
$ tmux switch -t <from> <to>

# e.g.
$ tmux rename -t great hi
```

## [#](#what-is-a-tmux-window)What is a Tmux Window?

The "child" under a Tmux Session. A session can have multiple windows ("children") to switch from.

To manipulate the window, we need to use the "Prefix" shortcuts. By default, Tmux uses `Ctrl+b`.

### [#](#1-create-a-new-window)1. Create a new window

This will create a new window and leave a number of the window we created to the Tmux bottom status line.

```
Ctrl + b + c
```

`0:zsh` is the first window, `1:zsh` is the second window.

### [#](#2-switch-between-windows)2. Switch between windows

We could choose the target window by specifying its number.

```
Ctrl + b + <window_number>

# e.g.
Ctrl + b + 2
```

### [#](#3-search-the-windows)3. Search the windows

We could look for the windows we created. The Tmux will go search the output / printout in the terminal.

```
Ctrl + b + f
```

### [#](#4-list-all-of-the-windows-in-this-session)4. List all of the windows in this session

The result screen is actually the same to search but with all of the windows we have.

```
Ctrl + b + w
```

### [#](#5-rename-current-window)5. Rename current window

By default, the window we created with `Ctrl+b+c` will have a name like "0:zsh" "1:shell". Sometimes we need special names to distinguish those windows (like naming the sessions) in a rather semantic way.

```
Ctrl + b + ,
```

### [#](#6-close-current-window)6. Close current window

```
Ctrl + b + &
```

## [#](#what-is-a-tmux-pane)What is a Tmux Pane?

Instead of Tmux windows to switch back and forth, a Tmux pane can help split the window into certain smaller blocks within the same screen. So that we could retain the information on the same screen.

### [#](#1-split-pane-vertically--horizontally)1. Split pane vertically / horizontally

Tmux makes it very easy to understand about pane splitting. The symbol `%` and `"` vividly explains how we are gonna split our screen.

```
# vertical split
Ctrl + b + "

# horizontal split
Ctrl + b + %
```

### [#](#2-kill-a-pane)2. Kill a pane

Usually when we run nothing in the terminal, we could close it immediately with `Ctrl+d` for most of the terminals. However if we are under some program like `Vim` or `SSH` and still hope to kill the pane forcefully, this will come into help.

```
Ctrl + b + x
```

### [#](#3-switch-between-panes)3. Switch between panes

Jump around the panes.

```
Ctrl + b + o
```

We also have numbers for each panes. Display the number of each pane and type the number to select the target pane.

```
# display pane number
Ctrl + b + q

# e.g.
Ctrl + b + q & 1
```

### [#](#4-move-the-current-pane-to-a-new-window)4. Move the current pane to a new window

Sometimes the pane we created is maybe too small to showcase everything in that terminal. We might need to consider moving the pane to a new window.

```
Ctrl + b + !
```

## [#](#summary)Summary

I personally think Tmux is a very good looking and helpful tool to allow everyone to control their terminals with only keyboards. Nowadays terminal apps like "iTerm" "cmder" all provided features similar to Tmux's "window" and "pane". Sometimes, these features are even more convenient than Tmux.

Tmux is really a powerful tool. But it needs time for us to digest the shortcut keys which is seemingly a "learning" curve to us all so that we could finally master using this powerful tool.