Notes for tmux Productive Mouse-Free Development written by Brian P. Hogan.
To start tmux:
To close the tmux session:
To create named session:
tmux new-session -s basic # creates a named session called "basic"
To detach from the current tmux session, press:
d stands for "detach".
If you have changed your
b to your own
We can list existing tmux sessions using the command:
To attach to a specific session, we use the
If we only have one session running, we can simply attach to it with
If we create a new tmux instance in the background using the command:
tmux new -s second_session -d
We can attach to this session by using the
tmux attach -t second_session
We can type
exit within a session to destroy that session, but we can also kill off sessions with the
tmux kill-session -t basic
Windows are similar to tabs in web browsers.
By using the
-n flag, we can name the first window in a session:
tmux new -s windows -n shell # creates a session called "windows"
To create a window in the current session, press:
Creating a window like this automatically brings the new window into focus.
To rename a windows, press:
We can cycle throw the windows with
n (next window) or
p (previous window).
By default, windows in tmux each have a number, starting at 0. We can quickly jump to the first window with
0, and the second window with
f to find a window by name (if we named our windows).
w to display a visual menu of our windows so we can select the one we'd like.
& or type
exit to close the current window.
Difference between panes and windows.
What's the difference between panes and windows?
In tmux, panes and windows are two different concepts that refer to distinct components of the terminal multiplexer.
- Windows: In tmux, a window is a single "view" or "tab" within the session. Each window occupies the entire terminal screen and can hold one or more panes. Windows are independent entities that can be created, closed, and switched between. They are typically used to organize and manage different tasks or applications within a tmux session. You can think of windows as similar to tabs in a web browser or a terminal emulator.
- Panes: A pane, on the other hand, is a subdivision of a window. It allows you to split a window into multiple resizable and scrollable regions. Each pane within a window can run its own command or application, effectively allowing you to work on multiple tasks simultaneously within a single window. Panes can be split both horizontally and vertically, and you can resize, rearrange, and interact with them independently.
To summarize, windows are the main containers that hold one or more panes, while panes are the subdivisions within a window where you can run different commands or applications. Windows provide a way to switch between different contexts or tasks, while panes enable multitasking within a single window.
% splits the current pane with horizontal layout.
" splits the current pane with vertical layout.
To cycle through the panes, press
Right to move around the panes.
x or type
To enter Command mode, press
? to get a list of all predefined tmux keybindings and the associated commands.
By default, tmux looks for configuration settings in two places. It first looks in
/etc/tmux.conf for a system-wide configuration. It then looks for a file called
.tmux.conf in the current user's home directory (
Many tmux users started out using GNU-Screen, which uses
a for its command prefix.
To redefine our tmux prefix to
a, add this code to our
set-option -g prefix C-a
-g switch, for "global", sets the option for al tmux sessions we create.
We can use the
unbind command to remove a keybinding:
Enter tmux's Command mode with
: and type this to apply the changes:
tmux adds a very small delay when sending commands, and this delay can interfere with other programs such as the Vim text editor. We can set this delay so it's much more responsive:
set -sg escape-time 1
The default index starts at zero. We can set it to one:
set -g base-index 1 # for windows
setw is the shortened version of
We can use the
bind command to define a new keybinding. Here we set
r so it reloads our main
.tmux.conf file in the current session:
bind r source-file ~/.tmux.conf
Don't forget to type
source-file ~/.tmux.conf to apply the configuration.
We can use the
display command to put a message in the status line when we the reloading finished:
bind r source-file ~/.tmux.conf \; display "Reloaded!"
You can see that we can bind a series of commands by separating the commands with the
\; character combination.
(Not suggested) We can define keybindings that don't require a prefix. For example, this makes
r reload the configuration file:
bind-key -n C-r source-file ~/.tmux.conf
a as our
Prefix, but programs such as Vim, Emacs and even the regular Bash shell also use that combination. We need to configure tmux to let us send that command through when we need it. We can also do that by binding the
send-prefix command to a keystroke, like this:
bind C-a send-prefix
The default keys for splitting panes can be difficult to remember, so let's set our own keys that we won't be able to forget. We'll set the horizontal split to
| and the vertical split to
bind | split-window -h
At first glance, this may look backwards. The
horizontalsplits, but to tmux, a vertical split means creating a new pane below the existing pane so the panes are stacked vertically on top of each other. A horizontal split means creating a new pane next to the existing one so the panes are stacked horizontally across the screen. So, in order to divide the window vertically, we use a "horizontal" split, and to divide it horizontally, we use a "vertical" split.
l as movement keys:
bind h select-pane -L
l to cycle through the windows:
bind -r C-h select-window -t :-
L to change the size of the panes:
bind -r H resize-pane -L 5
-r specify that we want the key to be repeatable, meaning we can press the prefix key only once and the continuously press the defined key within the repeat limit.
The default repeat limit is 500 milliseconds, and we can change that by setting the
repeat-time option to a higher value.
To enable mouse mode:
setw -g mode-mouse on