已复制
全屏展示
复制代码

tmux 个人常用配置整理

· 4 min read

使用场景:跑后台任务时使用,由于 Ubuntu 和 CentOS 的 tmux 的版本不一样,所以配置文件也不一样,下面是个人最习惯的 tmux 配置,主要思想是命令行快捷键实现最常用的功能,同时满足大多数的命令行配置习惯。

注意:如果是 crt 或 xshell 的话需要设置 alt 为 meta 键,使用 tmux 就不要使用鼠标了。

Ubuntu18.04 tmux 2.6 版本

# BASIC
set -g base-index 1               # window index from 1
set -g pane-base-index 1          # panel index from 1
set -g display-panes-time 5000    # select pane pause ms
set -g renumber-windows on        # renew window number after kill a window
set -gs escape-time 0             # No delay for escape key press
set -g history-limit 100000       # scrollback buffer n lines
set -g mouse off                  # mouse settings
setw -g automatic-rename off      # disable auto rename window
setw -g mode-keys vi              # vi like paste mode
setw -g monitor-activity off      # disable activity inform

# THEME
set -g message-style "bg=blue, fg=black"
set -g window-status-separator ""
set -g window-status-format " #I #W#F "
set -g window-status-current-format " #I #W#F "
set -g window-status-current-style "bg=red, fg=black"
set -g status-interval 10
set -g status-left-length 80
set -g status-right-length 80
set -g status-style "bg=blue, fg=black"
set -g status-left "#[bg=green, fg=black] [#S] "
set -g status-right "#[bg=green, fg=black] #(whoami)@#h #[bg=red] CPU: #(cut -d \" \" -f 1-3 /proc/loadavg) #[bg=green] T:#(numfmt --to=iec-i --suffix=B `free -b|awk 'FNR==2{print $2}'`) A:#(numfmt --to=iec-i --suffix=B `free -b|awk 'FNR==2{print $7}'`) #[bg=red] %m-%d %H:%M "

# Reload config: prefix + r
bind r source-file ~/.tmux.conf \; display-message "Reloaded!"

# Switch pane: Alt hjkl
bind -n M-h select-pane -L
bind -n M-j select-pane -D 
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# Select window: Alt Number
bind -n M-1 select-window -t 1
bind -n M-2 select-window -t 2
bind -n M-3 select-window -t 3
bind -n M-4 select-window -t 4
bind -n M-5 select-window -t 5
bind -n M-6 select-window -t 6
bind -n M-7 select-window -t 7
bind -n M-8 select-window -t 8
bind -n M-9 select-window -t 9

# Create pane: Alt+| Alt+_
bind -n M-_ splitw -v -c '#{pane_current_path}'
bind -n M-| splitw -h -c '#{pane_current_path}'

# Close panel and quit window: Alt+C Alt+Q
bind -n M-Q confirm-before -p "kill current pane #P? (y/n)" kill-pane

# Swap pane up and down: Alt+J Alt+K
bind -n M-Up swap-pane -U
bind -n M-Down swap-pane -D

# Resize panel: Alt+HJKL
bind -n M-H resize-pane -L 5
bind -n M-J resize-pane -D 5
bind -n M-K resize-pane -U 5
bind -n M-L resize-pane -R 5

# Pane full screen: Alt+Z
bind -n M-Z resize-pane -Z

CentOS7.7.1908 tmux 1.8 版本

# BASIC
set -g base-index 1                           # window index from 1
set -g pane-base-index 1                      # panel index from 1
set -g display-panes-time 5000                # select pane pause ms
set -g renumber-windows on                    # renew window number after kill a window
set -gs escape-time 0                         # No delay for escape key press
set-option -g history-limit 100000            # scrollback buffer n lines
set-option -g allow-rename off                # disable auto rename window
set-window-option -g automatic-rename off     # disable auto rename window
setw -g mode-keys vi                          # vi like paste mode
setw -g monitor-activity off                  # disable activity inform

# THEME
set -g status-fg black
set -g status-bg blue
set -g window-status-separator ""
set -g window-status-format " #I #W#F "
set -g window-status-current-format "#[bg=red]#[fg=black] #I #W#F "
set -g status-interval 10
set -g status-left-length 80
set -g status-right-length 80
set -g status-left "#[bg=green, fg=black] [#S] "
set -g status-right "#[bg=green, fg=black] #(whoami)@#h #[bg=red] CPU: #(cut -d \" \" -f 1-3 /proc/loadavg) #[bg=green] T:#(numfmt --to=iec-i --suffix=B `free -b|awk 'FNR==2{print $2}'`) A:#(numfmt --to=iec-i --suffix=B `free -b|awk 'FNR==2{print $7}'`) #[bg=red] %m-%d %H:%M "

# Reload config: prefix + r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."

# Switch pane: Alt hjkl
bind -n M-h select-pane -L
bind -n M-j select-pane -D 
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# Select window: Alt Number
bind -n M-1 select-window -t 1
bind -n M-2 select-window -t 2
bind -n M-3 select-window -t 3
bind -n M-4 select-window -t 4
bind -n M-5 select-window -t 5
bind -n M-6 select-window -t 6
bind -n M-7 select-window -t 7
bind -n M-8 select-window -t 8
bind -n M-9 select-window -t 9

# Create pane: Alt+| Alt+_
bind -n M-_ splitw -v -c '#{pane_current_path}'
bind -n M-| splitw -h -c '#{pane_current_path}'

# Close panel and quit window: Alt+C Alt+Q
bind -n M-Q confirm-before -p "kill current pane #P? (y/n)" kill-pane

# Swap pane up and down: Alt+J Alt+K
bind -n M-Up swap-pane -U
bind -n M-Down swap-pane -D

# Resize panel: Alt+HJKL
bind -n M-H resize-pane -L 5
bind -n M-J resize-pane -D 5
bind -n M-K resize-pane -U 5
bind -n M-L resize-pane -R 5

# Pane full screen: Alt+Z
bind -n M-Z resize-pane -Z
🔗

文章推荐