Tmux: Difference between revisions
| Line 2: | Line 2: | ||
== Quick Usage == | == Quick Usage == | ||
When starting tmux, you create a new session. Each session can have multiple windows (numbered 0..N). Each window can split into multiple panes. | When starting tmux, you create a new session. Each session can have multiple windows (numbered 0..N) and acts like tabs in a web browser. Each window can split into multiple panes and organized in a grid. | ||
Tmux Command Usage: | |||
{| class="wikitable" | {| class="wikitable" | ||
! width="30%" | Command | ! width="30%" | Command | ||
| Line 27: | Line 28: | ||
|} | |} | ||
=== Commands === | === Tmux Commands === | ||
All commands to tmux | All commands to tmux are prefixed with a key {{code|Ctrl-b}} (as opposed to {{code|Ctrl-a}} in screen). The default key bindings are quite unintuitive but can be changed to something a bit more usable. The tables below will show both the default and modified key bindings. | ||
General commands: | General commands: | ||
{| class="wikitable" | {| class="wikitable" | ||
! width="10%" | Command | ! width="10%" | Default Command | ||
! width="10%" | Modified Command | |||
! Description | ! Description | ||
|- | |- | ||
| d | | colspan="2" | d | ||
| Detach from this session | | Detach from this session | ||
|- | |- | ||
| $ | | colspan="2" | $ | ||
| Rename current session | | Rename current session | ||
|- | |- | ||
| s | | colspan="2" | s | ||
| Lists all sessions | | Lists all sessions | ||
|- | |- | ||
| t | | colspan="2" | t | ||
| Shows a clock in the current pane | | Shows a clock in the current pane | ||
|- | |- | ||
| ? | | colspan="2" | ? | ||
| Shows key bindings | | Shows key bindings | ||
|- | |- | ||
| : | | colspan="2" | : | ||
| Enters the tmux command prompt, where you can enter commands | | Enters the tmux command prompt, where you can enter commands | ||
|- | |- | ||
| [ | | [ | ||
| Enter copy mode | | / | ||
| Enter copy mode. You can use {{code|Vim}} key bindings if you set the {{code|mode-keys}} in the settings (see below). Exit copy mode by pressing {{code|Enter}}. | |||
|- | |||
| colspan="2" | w | |||
| Lists windows (it's also displayed at bottom) | |||
|} | |} | ||
Windows (tab) commands: | Windows (tab) commands: | ||
{| class="wikitable" | {| class="wikitable" | ||
! width="10%" | Command | ! width="10%" | Default Command | ||
! width="10%" | Modified Command | |||
! Description | ! Description | ||
|- | |- | ||
| c | | c | ||
| n | |||
| Creates a new window | | Creates a new window | ||
|- | |- | ||
| n | | n | ||
| , | |||
| Go to next window | | Go to next window | ||
|- | |- | ||
| p | | p | ||
| . | |||
| Go to previous window | | Go to previous window | ||
|- | |- | ||
| & | | & | ||
| X | |||
| Kills the current window | | Kills the current window | ||
|- | |- | ||
| , | | , | ||
| r | |||
| Rename the current window | | Rename the current window | ||
|- | |- | ||
| | | | ||
| | | < > | ||
| Reorder windows | |||
|} | |} | ||
Panes (split) commands. Enable mouse (see below) to make switching and resizing panes easy. | Panes (split) commands. Enable mouse (see below) to make switching and resizing panes easy. | ||
{| class="wikitable" | {| class="wikitable" | ||
! width="10%" | Command | ! width="10%" | Default Command | ||
! width="10%" | Modified Command | |||
! Description | ! Description | ||
|- | |- | ||
| % | | % | ||
| b (bisect) | |||
| Horizontal split (% is like 0/0, splits left/right) | | Horizontal split (% is like 0/0, splits left/right) | ||
|- | |- | ||
| " | | " | ||
| v | |||
| Vertical split | | Vertical split | ||
|- | |- | ||
| x | | colspan="2" | x | ||
| Close pane | | Close pane | ||
|- | |- | ||
| ! | | colspan="2" | ! | ||
| Close all other panes | | Close all other panes | ||
|- | |- | ||
| o | | o | ||
| Swap panes | | JKHL | ||
| Swap panes (modified bindings swap in the desired direction) | |||
|- | |- | ||
| q | | colspan="2" | q | ||
| Show pane numbers | | Show pane numbers | ||
|- | |- | ||
| z | | colspan="2" | z | ||
| 'Zooms' or maximizes the selected pane | | 'Zooms' or maximizes the selected pane | ||
|- | |||
| | |||
| jkhl | |||
| Selects pane in direction. (Or use mouse) | |||
|} | |} | ||
Revision as of 05:59, 4 May 2020
tmux is a terminal multiplexer similar to Screen but with some cool features such as split panes.
Quick Usage
When starting tmux, you create a new session. Each session can have multiple windows (numbered 0..N) and acts like tabs in a web browser. Each window can split into multiple panes and organized in a grid.
Tmux Command Usage:
| Command | Description |
|---|---|
| tmux ls | Lists all tmux sessions |
| tmux new -s session-name | Creates a new session named session-name |
| tmux a|attach N | Attaches to an existing session |
| tmux a|attach -t session-name | Attaches to an existing session by name |
| tmux kill-session -t session-name | Kills a session by name |
| tmux kill N | Kills a session by ID |
Tmux Commands
All commands to tmux are prefixed with a key Ctrl-b (as opposed to Ctrl-a in screen). The default key bindings are quite unintuitive but can be changed to something a bit more usable. The tables below will show both the default and modified key bindings.
General commands:
| Default Command | Modified Command | Description |
|---|---|---|
| d | Detach from this session | |
| $ | Rename current session | |
| s | Lists all sessions | |
| t | Shows a clock in the current pane | |
| ? | Shows key bindings | |
| : | Enters the tmux command prompt, where you can enter commands | |
| [ | / | Enter copy mode. You can use Vim key bindings if you set the mode-keys in the settings (see below). Exit copy mode by pressing Enter.
|
| w | Lists windows (it's also displayed at bottom) | |
Windows (tab) commands:
| Default Command | Modified Command | Description |
|---|---|---|
| c | n | Creates a new window |
| n | , | Go to next window |
| p | . | Go to previous window |
| & | X | Kills the current window |
| , | r | Rename the current window |
| < > | Reorder windows |
Panes (split) commands. Enable mouse (see below) to make switching and resizing panes easy.
| Default Command | Modified Command | Description |
|---|---|---|
| % | b (bisect) | Horizontal split (% is like 0/0, splits left/right) |
| " | v | Vertical split |
| x | Close pane | |
| ! | Close all other panes | |
| o | JKHL | Swap panes (modified bindings swap in the desired direction) |
| q | Show pane numbers | |
| z | 'Zooms' or maximizes the selected pane | |
| jkhl | Selects pane in direction. (Or use mouse) | |
To synchronize the input to all panes in the current window, enter :setw synchronize-panes. I bound this to Ctrl-b S for convenience in my .tmux.conf.
Configuration
Configuration can be set in ~/.tmux.conf file. Some useful settings are given below.
# Enable Vim key bindings in copy-mode
setw -g mode-keys vi
# Enable mouse, useful for selecting or resizing panes
set-option -g mouse on
# make scrolling with wheels work
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
# Move windows with C-b Left or C-b Right (arrow keys)
# bind-key -n C-S-Left swap-window -t -1\; select-window -t -1
# bind-key -n C-S-Right swap-window -t +1\; select-window -t +1
bind Left swap-window -t -1
bind Right swap-window -t +1
# Reload with 'Ctrl-b R'
bind R source-file ~/.tmux.conf \; display-message " Config reloaded..".
bind S setw synchronize-panes \; display-message " Synchronize panes".
See Also
- https://gist.github.com/MohamedAlaa/2961058
- Tmux for mere mortals with logical key bindings