Last active
June 11, 2025 17:00
-
-
Save zthxxx/bbbb37c100254d688236c21e8b977b85 to your computer and use it in GitHub Desktop.
My tmux config, migrate from gnu screen config via ChatGPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/tmux/tmux.conf | |
# https://quickref.me/tmux | |
# https://man7.org/linux/man-pages/man1/tmux.1.html | |
# Install | |
# | |
# ```bash | |
# mkdir -p ~/.config/tmux | |
# curl -L https://gist.github.com/zthxxx/bbbb37c100254d688236c21e8b977b85/raw/tmux.conf -o ~/.config/tmux/tmux.conf | |
# ``` | |
# | |
# or for development: | |
# | |
# ```bash | |
# git clone --depth=1 [email protected]:bbbb37c100254d688236c21e8b977b85.git tmux-config | |
# cd tmux-config | |
# mkdir -p ~/.config/tmux | |
# ln -fs "`pwd`/tmux.conf" ~/.config/tmux/tmux.conf | |
# | |
# # Tmux Plugin Manager https://github.com/tmux-plugins/tpm | |
# git clone --depth=1 https://github.com/tmux-plugins/tpm ~/.config/tmux/plugins/tpm | |
# ``` | |
###################### | |
# | |
# Note: | |
# - run shell `tmux list-keys -T prefix` to list all key bindings in prefix table | |
# - by default, <prefix> + Ctrl-O to rotate panes in current window | |
# | |
# | |
###################### | |
# | |
# -- Common Settings -- | |
# | |
# set-option: (alias set) | |
# set-window-option: (alias setw) | |
# Enable xterm keys to correctly interpret key sequences | |
setw -g xterm-keys on | |
# Eliminate delay for escape key sequences | |
set -s escape-time 0 | |
# Set the rate for repeating keys when held down | |
set -sg repeat-time 300 | |
# Enable focus events for terminal | |
set -s focus-events on | |
# Enable mouse support | |
set -g mouse on | |
# Automatically exit tmux when there are no sessions | |
set -sg exit-empty on | |
# Quietly enable UTF-8 support for status line | |
set -q -g status-utf8 on | |
# Quietly enable UTF-8 support for windows | |
setw -q -g utf8 on | |
# visual notification for window activity | |
set -g visual-activity off | |
# monitoring of window activity | |
setw -g monitor-activity on | |
setw -g bell-action any | |
# bell notification for the window | |
setw -g monitor-bell on | |
set -g default-terminal "xterm-256color" | |
# scroll history cache | |
set -g history-limit 65535 | |
# | |
# -- Window display -- | |
# | |
# Set the base index for windows to 1 instead of the default 0 | |
set -g base-index 1 | |
# Set the base index for panes to 1 instead of the default 0 | |
setw -g pane-base-index 1 | |
# Enable automatic renaming of windows based on the running application | |
setw -g automatic-rename on | |
# `b:` for basename | |
# set -g automatic-rename-format '#(print -P %1~)' | |
set -g automatic-rename-format '#{b:pane_current_path}' | |
# Automatically renumber the windows to have sequential indices after a window is closed | |
set -g renumber-windows on | |
# Automatically set terminal title to reflect the current program and directory | |
set -g set-titles on | |
# Display pane numbers for 2000 milliseconds (2 seconds) when the display-panes command is used | |
set -g display-panes-time 2000 | |
# Display messages for 2000 milliseconds (2 seconds) | |
set -g display-time 2000 | |
# Update status line every 1 second | |
set -g status-interval 1 | |
# Shortcut Key binding | |
# | |
# -- Prefix key -- | |
# remap prefix from 'Ctrl-B' to 'Ctrl-S' | |
# | |
unbind-key C-b | |
unbind-key C-s | |
set -g prefix C-s | |
# # type prefix key twice to send prefix key in nested tmux session | |
bind-key C-s send-prefix | |
# | |
# bind-key: (alias bind) | |
# Bind key key to command. Keys are bound in a key table. | |
# - By default (without -T), the key is bound in the **prefix** key table. | |
# - `-n` is an alias for `-T` root. | |
# - The `-r` flag indicates this key may repeat, see the `repeat-time` option. | |
# | |
# C: Ctrl | |
# M: Meta (Alt / Option) | |
# S: Shift | |
# | |
# https://man7.org/linux/man-pages/man1/tmux.1.html#KEY_BINDINGS | |
# | |
# <prefix> C-R to reload tmux config file | |
bind-key C-r 'source-file ~/.config/tmux/tmux.conf; display " tmux config reloaded! "' | |
# bind Alt + [123...=] to jump to window 1~12 | |
# `M` is `Meta key` | |
bind-key -n M-1 select-window -t :1 | |
bind-key -n M-2 select-window -t :2 | |
bind-key -n M-3 select-window -t :3 | |
bind-key -n M-4 select-window -t :4 | |
bind-key -n M-5 select-window -t :5 | |
bind-key -n M-6 select-window -t :6 | |
bind-key -n M-7 select-window -t :7 | |
bind-key -n M-8 select-window -t :8 | |
bind-key -n M-9 select-window -t :9 | |
bind-key -n M-0 select-window -t :10 | |
# bind Alt + Shift + [123...=] to move current panel to window 1~9 | |
bind-key -n 'M-!' join-pane -t :1 | |
bind-key -n 'M-@' join-pane -t :2 | |
bind-key -n 'M-#' join-pane -t :3 | |
bind-key -n 'M-$' join-pane -t :4 | |
bind-key -n 'M-%' join-pane -t :5 | |
bind-key -n 'M-^' join-pane -t :6 | |
bind-key -n 'M-&' join-pane -t :7 | |
bind-key -n 'M-*' join-pane -t :8 | |
bind-key -n 'M-(' join-pane -t :9 | |
# new panel in current window, | |
# the new panel position like: | |
# | |
# I | |
# J K L | |
# | |
bind-key k split-window -vb -c "#{pane_current_path}" | |
bind-key j split-window -v -c "#{pane_current_path}" | |
bind-key h split-window -hb -c "#{pane_current_path}" | |
bind-key l split-window -h -c "#{pane_current_path}" | |
bind-key -n F2 previous-window | |
bind-key -n F3 next-window | |
# add alternative in VSCode terminal | |
bind-key -n C-F2 previous-window | |
bind-key -n C-F3 next-window | |
bind-key -n F5 new-window -c "#{pane_current_path}" | |
bind-key -n F6 detach | |
# add alternative in VSCode terminal | |
bind-key -n C-F6 detach | |
bind-key -n F7 kill-pane | |
# F8: rename the current window, defaulting to its present name | |
bind-key -n F8 command-prompt -I "#W" "rename-window '%%'" | |
# Ctrl-F8: rename the current session, defaulting to its present name | |
bind-key -n C-F8 command-prompt -I "#S" "rename-session '%%'" | |
# bind F10 to toggle mouse scoll modle On/Off | |
bind-key -n F10 "display 'Turn Mouse #{?mouse,OFF,ON}'; set mouse #{?mouse,off,on};" | |
# https://fatfatson.github.io/2019/08/11/tmux内联使用方法/ | |
# | |
# 按 F12 切换到 nest tmux 模式,在 macos 里需要系统设置中取消 F12 占用 | |
# 1. 改 prefix 为 None,不再拦截快捷键 | |
# 2. 改 key-table 为 off,下面再绑定 off 下的 F12,使之能退出内嵌模式 | |
# 3. 改变 statusbar 颜色,以便知道已进入 nest-tmux 模式 | |
# 4. 如果已处于特殊模式,退出 | |
unbind-key -n F12 | |
bind-key -n F12 \ | |
set prefix None \;\ | |
set key-table nest-tmux \;\ | |
set status-style bg=colour23 \;\ | |
if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\ | |
refresh-client -S | |
# 在 nest-tmux 按键表里绑定 F12,用以恢复之前的设置,以退出该模式 | |
# The -u flag unsets an option, so a session inherits the option from | |
# the global options (or with -g, restores a global option to the default). | |
bind-key -T nest-tmux F12 \ | |
set -u prefix \;\ | |
set -u key-table \;\ | |
set -u status-style \;\ | |
refresh-client -S | |
# window move bindings | |
# <prefix> + <: move window to left one | |
# <prefix> + >: move window to right one | |
# https://github.com/tmux-plugins/tmux-pain-control/blob/master/pain_control.tmux#L29C1-L29C21 | |
bind-key -r "<" swap-window -d -t -1 | |
bind-key -r ">" swap-window -d -t +1 | |
# | |
# -- theme -- | |
# | |
# [Format](https://man7.org/linux/man-pages/man1/tmux.1.html#FORMATS) | |
# [STYLES](https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES) | |
# | |
# Status bar background to black | |
set -g status-position bottom | |
set -g status-style "bg=default" | |
# Status bar left to show Session Name | |
set -g status-left-length 60 | |
set -g status-left "#[fg=colour7]tmux: #[bold]#{session_name} | " | |
# Status bar right to show Hostname and Time | |
set -g status-right-length 60 | |
set -g status-right "#[fg=colour7] #{host} | %Y-%m-%d %H:%M:%S" | |
# Make the status bar look like have a top overline (by pane status border) | |
set -g pane-border-format '' | |
set -g pane-border-status bottom | |
## if only one pane in window, dot not show the active pane border color(green), instead show default color | |
## Only work for tmux 3.3+ | |
## | |
## The -F flag tells tmux to treat the first argument as a format, not a shell command. | |
if-shell -F '#{>=:#{version},3.3}' { | |
set -g pane-active-border-style "#{?pane_in_mode,fg=yellow,#{?synchronize-panes,fg=red,fg=#{?#{==:#{window_panes},1},default,green}}}" | |
} | |
# Windows style | |
set -g window-status-activity-style 'none' | |
set -g window-status-format '#{?window_activity_flag,#[underscore],#[none]}#[fg=colour12]#{window_index}.#{window_name}' | |
set -g window-status-current-format '#[fg=colour13,bold,reverse][#{window_index}.#{window_name}]' | |
set -g window-status-separator ' ' | |
set -g default-shell $SHELL | |
# plugins | |
## Tmux Plugin Manager https://github.com/tmux-plugins/tpm | |
set -g @plugin 'tmux-plugins/tmp' | |
## https://github.com/tmux-plugins/tmux-resurrect | |
set -g @plugin 'tmux-plugins/tmux-resurrect' | |
## custom key bindings | |
## https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/custom_key_bindings.md | |
## | |
## <prefix> + Alt-Shift-S to save current tmux session | |
## <prefix> + Alt-Shift-R to restore tmux session | |
## S for Save, R for Restore | |
set -g @resurrect-save 'M-S' | |
set -g @resurrect-restore 'M-R' | |
run '~/.config/tmux/plugins/tpm/tpm' |
Author
zthxxx
commented
Jun 13, 2024

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment