Tmux Configuration


tmux is one of the best tools you can use on a UNIX based system.
It’s a beefed up version of screen, a terminal multiplexer.

It’s mainly used trough ssh but i often use it locally as well.

Install

1
sudo apt install tmux

Tweaking

The basic tmux install can be configured an extended with plugins.
Some of the configuration is necessary to use tmux comfortably.

I’m sharing my .tmux.conf file as template.
This uses a sane keybinding layout and various plugins and tweaks.
You can try this as your .tmux.conf file after backing up yours.
The configuration file is located in ~/.tmux.conf.
You can install the plugins after tmux attach with Command + Shift + i.

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# scrollback size
set -g history-limit 10000

################################
# Keybinds
###############################

# Changing ctrl b to ctrl a as the command button
unbind C-b
set -g prefix C-a

# set first window to index 1 (not 0) to map more to the keyboard layout
set -g base-index 1
set -g pane-base-index 1

# pass through xterm keys
set -g xterm-keys on

# Keep your finger on ctrl, or don't, same result
bind-key C-d detach-client
bind-key C-p paste-buffer

# Redraw the client (if interrupted by wall, etc)
bind R refresh-client

# reload tmux config with ctrl + a + r
unbind r
bind r \
source-file ~/.tmux.conf \;\
display 'Reloaded tmux config.'

# Vertical splits with g or C-g
unbind g
unbind C-g
bind-key g split-window -h
bind-key C-g split-window -h

# Horizontal splits with v or C-h
unbind h
unbind C-h
bind-key h split-window
bind-key C-h split-window

# Ctrl + a + o rename window
# unbind o
# unbind C-o
# bind-key C-o rename-window

# Using the mouse to switch panes
set -g mouse-utf8 on
set -g mouse on

# Ctrl - t or t new window
unbind t
unbind C-t
bind-key t new-window
bind-key C-t new-window

# Ctrl - w or w to kill panes
unbind w
unbind C-w
bind-key w kill-pane
bind-key C-w kill-pane

# C + control q to kill session
unbind q
unbind C-q
bind-key q kill-session
bind-key C-q kill-session

# Switching panes with alt
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Ctrl + a + n : New session
unbind n
unbind C-n
bind-key n new-session
bind-key C-n new-session

# Ctrl + a + Pagedown : Next window
#unbind Pagedown
unbind Pagedown
bind-key Pagedown next-window

# Ctrl + a + Pagup : Previous window
#unbind Pageup
unbind Pageup
bind-key Pageup previous-window

# Zoom with ctrl + a + ctrl + '+'
#unbind C-+
#bind C-+ \
#new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read'\;\
#swap-pane -s tmux-zoom.0 \;\
#select-window -t tmux-zoom

# Zoom back ctrl + a + ctrl + '-'
#unbind C--
#bind C-- \
# last-window \;\
# swap-pane -s tmux-zoom.0 \;\
# kill-window -t tmux-zoom

# Visual Activity Monitoring between windows
setw -g monitor-activity on
set -g visual-activity on

# Show tmux positions in titles
set -g set-titles on

# Set up a basic panel structure for command + ctr D
bind D source-file ~/.tmux/dev

# Attach to a session if runs otherwise create a new one
new-session -n $HOST

# Copy from tmux to system clipboard
# Needs xclip -> sudo apt install xclip
bind -t vi-copy y copy-pipe "xclip -sel clip -i"

#####################################
# Plugins
#https://github.com/tmux-plugins/tpm
####################################

#####################################
# tpm plugin manager
# https://github.com/tmux-plugins/tpm
#####################################
set -g @plugin 'tmux-plugins/tpm'

#####################################
# tmux-sensible - basline settings that get overwritten from .tmux.conf
# https://github.com/tmux-plugins/tmux-sensible
######################################
#set -g @plugin 'tmux-plugins/tmux-sensible'

#####################################
# tmux-resurrect - save and reload sessions and windows after a restart
# https://github.com/tmux-plugins/tmux-resurrect
# Default keybinds : save - command + c + s && restore command + c + r
######################################
set -g @plugin 'tmux-plugins/tmux-resurrect'
### tmux-resurrect extra settings ###
# keep vim sessions after reboot
set -g @resurrect-strategy-vim 'session'
# keep pane contents
set -g @resurrect-capture-pane-contents 'on'
# restore bash history
set -g @resurrect-save-bash-history 'on'
### /tmux-resurrect extra settings ###

######################################
# tmux-continuum - automatically save and restore tmux sessions
# https://github.com/tmux-plugins/tmux-continuum
#####################################
set -g @plugin 'tmux-plugins/tmux-continuum'
# Restore last saved enviroment
set -g @continuum-restore 'on'
# Set autosave interval
set -g @continuum-save-interval '5'
# Show continiuum state in statusbar
#set -g status-right 'Continuum status: #{continuum_status}'
# Starting tmux with system https://github.com/tmux-plugins/tmux-continuum/blob/master/docs/automatic_start.md

######################################
# tmux-yank - advanced copy mode
# https://github.com/tmux-plugins/tmux-yank
#####################################
set -g @plugin 'tmux-plugins/tmux-yank'

# initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

Plugins

Keybindings

Keybinding Command
Ctrl + a Command
Command + t New window
Command + w Kill pane
Command + q Kill session
Command + r Reload tmux config
Command + z Zoom to pane
Command + $ Rename session
Command + , Rename window
Command + g Split vertically
Command + h Split horizontally
Command + ? List keyboard shortcuts
Command + : Command prompt
Command + s List sessions
Command + Ctrl + r Reload session
Command + Ctrl + s Save session
Command + Shift + i Install plugins

Copy and paste in mouse mode

Copy:

  • Enter scroll mode with the mouse wheel.
  • Select the text and press y.
  • This copies the text into the clipboard.
  • Exit scroll mode with escape.

Advanced copy:

  • Enter scroll mode with the mouse wheel.
  • Select the text and press Y.
  • This copies the text into the terminal buffer and the clipboard.
  • Exit scroll mode with escape.