Skip to content

Instantly share code, notes, and snippets.

@zthxxx
Last active March 8, 2024 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zthxxx/bbbb37c100254d688236c21e8b977b85 to your computer and use it in GitHub Desktop.
Save zthxxx/bbbb37c100254d688236c21e8b977b85 to your computer and use it in GitHub Desktop.
My tmux config, migrate from gnu screen config via ChatGPT
# ~/.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 -sL https://gist.github.com/zthxxx/bbbb37c100254d688236c21e8b977b85/raw/tmux.conf -o ~/.config/tmux/tmux.conf
# ```
#
# or:
# ```bash
# gcl git@gist.github.com:bbbb37c100254d688236c21e8b977b85.git tmux-config
# cd tmux-config
# mkdir -p ~/.config/tmux
# ln -fs "`pwd`/tmux.conf" ~/.config/tmux/tmux.conf
# ```
#
######################
#
# -- 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
set -g prefix 'C-s'
#
# 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.
#
# C: Ctrl
# M: Meta
# S: Shift
#
# https://man7.org/linux/man-pages/man1/tmux.1.html#KEY_BINDINGS
#
# <prefix> Ctrl+R to reload tmux config file
bind-key C-r 'source-file ~/.config/tmux/tmux.conf; display " tmux config reloaded! "'
# bind Alt + [123...=] 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
# 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
# bind F8 to rename current tmux window
bind-key -n F8 command-prompt "rename-window %%"
# bind F12 to toggle mouse scoll modle On/Off
bind-key -n F12 "display 'Turn Mouse #{?mouse,OFF,ON}'; set mouse #{?mouse,off,on};"
#
# -- 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
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 ' '
@zthxxx
Copy link
Author

zthxxx commented Jun 19, 2023

image

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