start new:
tmux
start new with session name:
tmux new -s myname
attach:
tmux a # (or at, or attach)
attach to named:
tmux a -t myname
list sessions:
tmux ls
kill session:
tmux kill-session -t myname
detach all other clients: tmux detach -a
Alternatively you can hit prefix + D to bring up a list of attached clients and choose to detach the ones you want.
In tmux, hit the prefix ctrl+a
and then:
:new<CR> new session
s list sessions
$ name session
( previous session
) next session
c new window
w list windows
f find window
, name window
& kill window
C-h previous window
C-l next window
H swap with previous window
L swap with next window
| vertical split
- horizontal split
o swap panes
q show pane numbers
x kill pane
+ break pane into window (e.g. to select text by mouse to copy)
⍽ space - toggle between layouts
: Last pane
C-q Last pane
q Show pane numbers, when the numbers show up type the key to goto that pane)
{ Move (Swap) the current pane Up
} Move (Swap) the current pane Down
l Move to the pane on the right
h Move to the pane on the left
k Move to the pane above
j Move to the pane below
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:
PREFIX CTRL + Up resize-pane -U (Resizes the current pane upward)
PREFIX CTRL + Left resize-pane -L (Resizes the current pane left)
PREFIX CTRL + Right resize-pane -R (Resizes the current pane right)
PREFIX CTRL + Down resize-pane -D (Resizes the current pane down)
Pressing PREFIX '[' (just open square bracket) 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:
setw -g mode-keys vi
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.
Use 'v' to go into selection mode, just like vim's visual mode. Use 'y' to copy. This will push it to tmux buffer stack.
You can see whats in the buffer stack by using 'tmux list-buffers' or the shortcut PREFIX + #.
To load somthing to tmux buffer, you can use 'tmux loadb' with stdin like so ./run_script_with_some_stdout.sh | tmux loadb -
Pasting from the buffer stack : PREFIX + p or PREFIX + ].
Text from the buffer stack can aslo be piped using 'tmux showb | ... ' or 'tmux saveb - | ... '.
d detach
t big clock
? list shortcuts / help
: prompt
You can use the tmux command move-window
to move windows between sessions.
move-window [-s src-window] [-t dst-window]
Here src-window and dst-window are of the format session:window
where session
and window can be names of ids. You dont have to specify the session you are in
if either of those is the source or the target. If you are on the window that
has to be moved, then you can completely skip the -s argument.
You can use respawn-window
command. There variants to the respawn-
command.
# Mouse support - set to on if you want to use the mouse
* setw -g mode-mouse off
* set -g mouse-select-pane off
* set -g mouse-resize-pane off
* set -g mouse-select-window off
# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
# Center the window list
set -g status-justify centre
# Maximize and restore a pane
unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp