Post

Tmux Session Cheatsheet

tmux sessions

Prerequisites

  • Tmux installed.
  • The default tmux prefix is ctrl-b. Knowing this, you can now run the commands from the ‘within tmux’ section below.
  • Commands that begin with tmux are to be run on the command line.

Tmux config

tmux.config

You can use the config to remap keys. see my tmux config file

Open tmux.config

1
vi ~/.tmux.conf

Source new tmux config file changes

1
:source-file ~/.tmux.conf

Create a new tmux session and give it a name

1
tmux new -s the_name

Attach session

Go back into an existing session.

1
attach -t Session

List sessions

1
tmux ls

Exit session

Exit the session but keep it alive so you can attach to it again.

1
tmux detach

Kill all sessions

1
tmux kill-server

Kill a specific session

first list the sessions

1
tmux list-sessions

or

1
tmux ls

Then choose one to kill

1
tmux kill-session -t targetSession

Scroll

Enable vi navigation keys to move the cursor around. copy and paste content from previous commands using your vim keys

1
prefix [

entering vim mode and copying some output using vim yank

Exit scroll mode

1
q

Attach an existing session to your current shell window

  • tmux attach -t (for target) name of session

Plugins

add plugins to your tmux config

1
2
3
4
5
# list plugins
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'jimeh/tmux-themepack'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

Install plugins

  • prefix, shift i

Plugin config

config plugins using tmux.config

1
2
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'

Troubleshooting

  • macOS fix for “warning: reattach-to-user-namespace: unsupported new OS, trying as if it were 10.10”
1
brew upgrade reattach-to-user-namespace

more info

More information

more info

My tmux config file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix


set -g default-terminal "screen-256color"

# horizonal and vertical split planes
unbind %
bind | split-window -h

unbind '"'
bind - split-window -v


# resize panes
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5

# maximise pane
bind -r m resize-pane -X

set -g mouse on

bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection

unbind -T copy-mode-vi MouseDragEnd1Pane

# source config with prefix r
unbind r
bind r source-file ~/.tmux.conf

# plugin manager
set -g @plugin 'tmux-plugins/tmp'

# list plugins
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'jimeh/tmux-themepack'

set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'


set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'

set -g @themepack 'powerline/default/cyan'



# keep at the bottom
run '~/.tmux/plugins/tpm/tpm'


# restore vim buffers
set -g @resurrect-processes 'vim:all'

Within Tmux

see tmux commands

This post is licensed under CC BY 4.0 by the author.