tmux - where have you been all my life? Source

1---
2title: 'tmux - where have you been all my life?'
3date: '2016-05-19'
4published_at: '2016-05-19T16:28:00.004+10:00'
5tags: ['command line', 'linux', 'screen', 'tmux', 'unix']
6author: 'Gavin Jackson'
7excerpt: 'Yesterday I discovered tmux - what an awesome command line tool! So powerful, yet so easy to use (and configure!). If you haven''t heard of tmux before, but have used GNU screen then tmux is basically...'
8updated_at: '2021-04-16T09:57:26.603+10:00'
9legacy_url: 'http://www.gavinj.net/2016/05/tmux-where-have-you-been-all-my-life.html'
10---
11
12[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrtvMuO7tiBvzakBZf0o2xdnmAIPbrve21KIL9yfUSsn9kvlECbX7fcd6Cba-NZfQWBZ4Dy12woMQ8zD5LLRVxQbDSthMWOlndNgPsSYeUT9m5Keg4LPrxmYdbPjzeXqoRsNGOtPaCiC0/s640/tmux.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrtvMuO7tiBvzakBZf0o2xdnmAIPbrve21KIL9yfUSsn9kvlECbX7fcd6Cba-NZfQWBZ4Dy12woMQ8zD5LLRVxQbDSthMWOlndNgPsSYeUT9m5Keg4LPrxmYdbPjzeXqoRsNGOtPaCiC0/s1600/tmux.png)
13
14Yesterday I discovered **tmux** - what an awesome command line tool!
15
16So powerful, yet so easy to use (and configure!).
17
18If you haven't heard of tmux before, but have used GNU screen then tmux is basically an enhanced screen replacement.
19
20It allows you to set up a set of windows (with panes and tabs), detach from the session, and later reattach. You can also attach multiple users to a tmux session (which is great for pair programming - or if you are giving someone a tour of a server).
21
22Interested You should buy this book - it's short and great:
23
24https://pragprog.com/book/bhtmux/tmux
25
26**Basic commands:**
27
28** **
29
30**New Session**
31
32tmux new -s [-d]
33
34**Attach to Session**
35
36tmux attach -t
37
38**Kill Session**
39
40tmux kill-session -t
41
42**List Sessions**
43
44tmux ls
45
46All key commands start with a prefix (by default it is configured to be **ctrl+b**), most people change this to ctrl+a by the looks of things.
47
48**Windows**
49
50New Window (**c**)
51
52Select Window (**0-9**)
53
54Rename Window (**,**)
55
56Detach (**d**)
57
58**Panes**
59
60Vertical Split (**"**) *- a good replacement for this is (**|**)*
61
62Horizontal Split (**%**) *- a good replacement for this is (**-**)*
63
64Swap Panes (**{}**)
65
66Select Pane **UDLR**
67
68Close Pane (**x**)
69
70Cycle Pane (**o**)
71
72Turn Page Into a New Window (**!**)
73
742. Here is my current tmux config (place in ~/.tmux.conf):
75
76```
77# Setting the prefix from C-b to C-a
78set -g prefix C-a
79
80# Free the original Ctrl-b prefix keybinding
81unbind C-b
82
83#setting the delay between prefix and command
84set -s escape-time 1
85
86# Ensure that we can send Ctrl-A to other apps
87bind C-a send-prefix
88
89# Set the base index for windows to 1 instead of 0
90set -g base-index 1
91
92# Set the base index for panes to 1 instead of 0
93setw -g pane-base-index 1
94
95# Reload the file with Prefix r
96bind r source-file ~/.tmux.conf \; display "Reloaded!"
97
98# splitting panes
99bind | split-window -h
100bind - split-window -v
101
102# moving between panes
103bind h select-pane -L
104bind j select-pane -D
105bind k select-pane -U
106bind l select-pane -R
107
108# Quick pane selection
109bind -r C-h select-window -t :-
110bind -r C-l select-window -t :+
111
112# Pane resizing
113bind -r H resize-pane -L 5
114bind -r J resize-pane -D 5
115bind -r K resize-pane -U 5
116bind -r L resize-pane -R 5
117
118# mouse support - set to on if you want to use the mouse (tmux > 2.1)
119#set -g mouse on
120#bind m set -g mouse on \; display "Mouse ON"
121#bind M set -g mouse off \; display "Mouse OFF"
122
123# mouse support - set to on if you want to use the mouse (tmux < 2.1)
124#set -g mode-mouse on
125#set -g mouse-resize-pane on
126#set -g mouse-select-pane on
127#set -g mouse-select-window on
128#bind m set -g mode-mouse on \; set -g mouse-resize-pane on \; set -g mouse-select-pane on \; set -g mouse-select-window on \; display "Mouse ON"
129#bind M set -g mode-mouse off \; set -g mouse-resize-pane off \; set -g mouse-select-pane off \; set -g mouse-select-window off \; display "Mouse OFF"
130
131# Set the default terminal mode to 256color mode
132set -g default-terminal "screen-256color"
133
134# enable activity alerts
135setw -g monitor-activity on
136set -g visual-activity on
137
138# set the status line's colors
139set -g status-fg white
140set -g status-bg black
141
142setw -g window-status-style fg=cyan
143setw -ga window-status-style bg=default
144setw -ga window-status-style dim
145setw -g window-status-current-style fg=white
146setw -ga window-status-current-style bg=black
147setw -ga window-status-current-style bright
148set -g pane-border-style fg=green
149set -ga pane-border-style bg=black
150set -g pane-active-border-style fg=white
151set -ga pane-active-border-style bg=yellow
152set -g message-style fg=white
153set -ga message-style bg=black
154set -ga message-style bright
155set-window-option -g window-status-current-style bg=black
156set-window-option -ga window-status-current-style fg=yellow
157set-window-option -ga window-status-current-style dim
158
159# Status line left side
160set -g status-left-length 40
161set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
162
163# Status line right side
164# 15% | 28 Nov 18:15
165set -g status-right "#(~/battery Discharging) | #[fg=cyan]%d %b %R"
166
167# Update the status bar every sixty seconds
168set -g status-interval 60
169
170# Center the window list
171set -g status-justify centre
172
173# enable vi keys.
174setw -g mode-keys vi
175
176# shortcut for synchronize-panes toggle
177bind C-s set-window-option synchronize-panes
178
179# Log output to a text file on demand
180bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"
181```
182
183
184