Level 0 - Concepts and your First Configuration
Concepts
Tmux has 3 concepts you should know about:
- Panes contain a single terminal
- Windows are a group of panes
- Sessions are a group of windows
When you run tmux
, tmux will spawn one session, which contains one window, and that window contains one pane, which is running a terminal. If you type exit
or press CTRL-d
, that closes the pane, but since there was only one pane in the window, the window also closes. And since the last window closed, the session also closes, and you are back to your normal terminal emulator without tmux running.
Intro to tmux keybindings
If you already know how to do the following, you may skip this section.
Along with understanding the concepts, you should know how to perform some of the basic actions in tmux (later we will change the keybinds when configuring tmux).
Prefix key
Many tmux operations require the user to prefix the hotkey with the "prefix" key, which defaults to Ctrl-b
. For example, to create a new window, you first press the prefix key, then press the c
key. It looks like two steps, but if you're new to tmux, it might make more sense to think of it like the following:
- Hold the
Ctrl
key - Then tap the
b
key, and let go of theCtrl
key - Then tap the
c
key
Once you get used to that, you can start tapping both Ctrl
and b
at the same time (but don't get too used it, as we will change the prefix key later in this page).
Basic actions
You can view some of the basic default keybindings by searching "tmux keybindings" in a search engine like DuckDuckGo, or finding a cheatsheet like this. You can find keybindings by running tmux list-keys
or man tmux(1)
.
Here are the keybinds that I use the most:
Ctrl-b
"
: Split pane horizontallyCtrl-b
%
: Split pane verticallyCtrl-b
Arrow keys: Focus between panesCtrl-b
c
: Create new windowCtrl-b
n
: Go to next window
Now we'll start making our first configuration changes.
Changing the Prefix Key
The first change we will make is to change tmux's prefix key. First I'll explain why I change the default prefix key, and then I'll give some suggestions for some other options you can use for the prefix key.
Why did I change the prefix key?
Simply, the B key is too far away from the CTRL key for me. It requires me to stretch my index finger to reach it, and its very uncomfortable for me to do. Because of that, and because I've used GNU Screen in the past, I switched to using C-a as the prefix.
Some time after that though, I switched my keyboard layout to Colemak DH and learned how to type properly, i.e., using all of my fingers, starting at the home row. Because of that though, pressing C-a felt much different because now that my pinky rests on the A key, I need to shift my hand my one column to the left to then press the CTRL key with my pinky and the A key with my ring finger.
I then switched to C-o (C-; in QWERTY) as my prefix key because of the above, and also because I wanted to split the work across my hands, as opposed to only using my left hand to press CTRL and A.
Alternatives choices for the prefix key
You can use C-a, which is the prefix used in GNU Screen. I've seen one user use C-SPACE, so having one of the keys be on the thumb, but another option could be to have the CTRL modifier be on the thumb rather than the pinky.
The Initial Config
If you rather not change the prefix, you can skip this step. Otherwise, place the following in ~/.config/tmux/tmux.conf
# use C-o (right pinky homerow) as prefix
unbind C-b
set -g prefix C-o
bind C-o send-prefix