tmux

Installing tmux

Install wiki

Platform Install Command
Debian or Ubuntu apt install tmux
macOS (using Homebrew) brew install tmux

Useful cmd / shortcut

Cmd Shortcut Description
man tmux Show tmux documentation
tmux new -s [Session Name] Create a new tmux session
tmux a -t [Session Name] Attach to an existing session
tmux detach prefix + d Detach current session
tmux kill-session -t [Session Name] Delete a specific Session
prefix + r Source the .tmux.conf file
prefix + , Rename current active window
prefix + c Create new window
prefix + & Kill current window
prefix + n Next window
prefix + p Previous window
prefix + w List all Sessions and windows
prefix + | Split windows left and right
prefix + - Split windows up and down
Ctrl + h/j/k/l Move to the left/down/up/right pane, enabled by vim-tmux-navigator
prefix + h/j/k/l Resize pane, direction keys can be repeated
prefix + m Maximize/Unmaximize current pane

Personal configuration

All key remappings and options setting go into~/.tmux.conf (Remeber to source the config file after you make changes)

My prefix key is Ctrl-a

1
2
$ touch ~/.tmux.conf
$ tmux source ~/.tmux.conf # run this line after you make changes

Plugins

Install tpm

First, we will clone tpm into ~/.tmux folder under the home folder

1
2
3
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

# Otherwise you may get "~/.tmux/plugins/tpm/tpm' returned 127" by executing the following steps

Installing Plugins

  1. Add new plugin to ~/.tmux.conf with set -g @plugin '...'
  2. Make sure run -b '~/.tmux/plugins/tpm/tpm' is at the bottom of your .tmux.conf
  3. Press prefix + I (capital i, as in Install) to fetch the plugin. (default prefix is ctrl+b)

Uninstalling Plugins

  1. Remove (or comment out) plugin from the list.
  2. Press prefix + alt + u (lowercase u as in uninstall) to remove the plugin. Or you can manually delete the plugins stored in ~/.tmux/plugins/

Theme

Dracula Theme

A dark theme for Atom, Alfred, Emacs, Highlight.js, Hyper, iTerm, JetBrains, Pygments, Slack, Sublime Text, TextMate, Terminal.app, Vim, Xcode, Zsh, and many more.

Others

Updated my arch linux server and now I get tmux: need UTF-8 locale (LC_CTYPE) but have ANSI_X3.4-1968

The same exact thing happened to me. Building on what Thomas said above, I was able to fix it by uncommenting en_US.UTF-8 UTF-8 in my /etc/locale.gen file (previously none of the lines had been uncommented), then running locale-gen.

My Configuration

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
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# avoid delay on Esc
set -sg escape-time 0

# split panes using | and -
unbind %
unbind '"'
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# source configuration file
unbind r
bind r source-file ~/.tmux.conf

# resize panes using hjkl and m for full size
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
bind -r m resize-pane -Z

# longer scrollback
set -g history-limit 100000

# This binds ctrl-k to the tmux clear-history command.
# The -n after bind makes it so you don't have to issue the tmux command prefix (ctrl-b by default)
bind -n C-k clear-history

# enable mouse mode
set -g mouse on
set -g mode-keys vi
# set -g mouse-resize-pane on
# set -g mouse-select-pane on
# set -g mouse-select-window on

# list of tmux plugins
# tmux package manager
set -g @plugin 'tmux-plugins/tpm'

# dracula tmux-theme
set -g @plugin 'dracula/tmux'
# available plugins: battery, cpu-usage, git, gpu-usage,
# ram-usage, network, network-bandwidth, network-ping,
# attached-clients, network-vpn, weather, time
set -g @dracula-plugins "cpu-usage ram-usage network-ping weather"
set -g @dracula-show-location false
set -g @dracula-show-fahrenheit false
set -g @dracula-ping-server "google.com"
set -g @dracula-ping-rate 30
set -g @dracula-refresh-rate 5
# available colors: white, gray, dark_gray, light_purple, dark_purple, cyan, green, orange, red, pink, yellow
# set -g @dracula-[plugin-name]-colors "[background] [foreground]"
set -g @dracula-cpu-usage-colors "light_purple dark_gray"
set -g @dracula-ram-usage-colors "cyan dark_gray"
set -g @dracula-network-ping-colors "green dark_gray"
set -g @dracula-weather-colors "orange dark_gray"

# using <C-h/j/k/l> to switch panes
set -g @plugin 'christoomey/vim-tmux-navigator'
# set -g @plugin 'jimeh/tmux-themepack'
# persist tmux sessions after computer restart
set -g @plugin 'tmux-plugins/tmux-resurrect'
# automatically saves sessions for you every 15 minutes
set -g @plugin 'tmux-plugins/tmux-continuum'

set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
# Initialize TPM
run '~/.tmux/plugins/tpm/tpm'

Ref

Everything you need to know about tmux – Plugins Manager

tmux Key Combinations


tmux
http://example.com/2023/04/20/tmux/
作者
臣皮蛋
发布于
2023年4月20日
许可协议