Skip to content

Instantly share code, notes, and snippets.

@dcai
Last active March 25, 2024 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcai/3824286 to your computer and use it in GitHub Desktop.
Save dcai/3824286 to your computer and use it in GitHub Desktop.
tmux config
# Author: Dongsheng Cai
#
# Gist: https://gist.github.com/dcai/3824286
#
# c-d to close shell
# <prefix> s to switch to another session
# <prefix> f to find a window
# <prefix> o to switch to another panel
# <prefix> ! to close other panes except current one
# <prefix> x Kill the current pane
# <prefix> & kill the current window
# <prefix> w to list windows
# <preifx> " or - split pane horizontally
# <prefix> % or | split pane vertically
# <prefix> , rename current window
# <prefix> $ rename current session
# <prefix> ? list key bind
# Change prefix to ctrl+q
# c-b breaks less and vim
# c-a breaks emacs and bash emacs mode
unbind C-b
set -g prefix C-q
# Switch to last window
unbind l
bind-key C-q last-window
unbind C-Left
unbind C-Right
bind-key C-p previous-window
bind-key C-n next-window
bind-key C-Left previous-window
bind-key C-Right next-window
unbind r
bind-key r source-file ~/.tmux.conf \; display-message ".tmux.conf reloaded"
# unbind o
# moving between panes with vim movement keys
bind h select-pane -L
bind l select-pane -R
bind j select-pane -D
bind k select-pane -U
# easy to remembe split pane commands
bind | split-window -h
bind - split-window -v
# set -g bell-action any
# set -g visual-activity on
# setw -g monitor-activity on
set -g aggressive-resize off
set -g base-index 1
set -g default-terminal screen-256color
set -g mode-style "fg=red, bg=blue"
set -g mouse on
set -g set-titles on # Attempt to set the client terminal title
set -g status-interval 1
set -g status-left '[#S] ' # this is tmux session name
set -g status-left-length 20
set -g status-position top
# set -g status-right '#[fg=yellow]#H#[default]'
set -g status-right '#[fg=green][#[fg=white,bold]%d, %h #[bg=green,fg=white,bold]%H:%M:%S#[default]#[fg=blue]]'
set -g status-style "fg=white,bg=green"
set -g window-status-current-style "fg=black,bg=white"
set -g window-status-style "fg=white,bg=default"
setw -g automatic-rename on # auto set window title
setw -g mode-keys vi
setw -g pane-base-index 1
# Author: Dongsheng Cai
# Email: d@tux.im
# Gist: https://gist.github.com/dcai/3824286
#
# config for tmux 3.3 and above
#
# c-d to close shell
##### Pane
# <prefix> % split pane vertically
# <preifx> " split pane horizontally
# <prefix> ; last pane
# <prefix> o to switch to another pane
# <prefix> x Kill the current pane
# <prefix> z zoom active pane
# <prefix> ! Break the current pane out of the window.
# <prefix> $ rename current session
# <prefix> & kill the current window
# <prefix> , rename current window
# <prefix> ? list key bind
# <prefix> f to find a window
# <prefix> l last window
# <prefix> s to switch to another session
# <prefix> w to list windows
# Change prefix to ctrl+q
# c-b breaks less and vim
# c-a breaks emacs and bash emacs mode
unbind-key C-b
set-option -g prefix C-g
bind-key C-g last-window
set-window-option -g clock-mode-colour colour5
# unbiond c-o to rotate through the panes
unbind-key C-o
unbind-key r
bind-key r source-file ~/.tmux.conf \; display-message "tmux config reloaded"
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
# set-option -g default-shell /usr/bin/fish
bind-key . split-window -h -l 33%
# next and prev window
bind-key C-n select-window -t :+1
bind-key C-p select-window -t :-1
# resize panes
bind-key C-h resize-pane -L 10
bind-key C-l resize-pane -R 10
bind-key C-j resize-pane -D 10
bind-key C-k resize-pane -U 10
bind-key \ command-prompt -k -p key { list-keys -1N "%%" }
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
# set-option -g bell-action any
# set-option -g visual-activity on
# set-window-option -g monitor-activity on
set-option -g aggressive-resize off
set-option -g base-index 1
set-option -g default-terminal screen-256color
# set-option -g default-terminal "${TERM}"
set-option -g terminal-overrides ',xterm-256color:RGB'
set-option -as terminal-overrides ',*:Smulx=\E[4::%p1%dm' # undercurl support
set-option -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' # underscore colours - needs tmux-3.0
set-option -g mouse on
set-option -g set-titles on # Attempt to set-option the client terminal title
set-option -g status-interval 1
set-option -g status-position top
set-option -g escape-time 10
set-option -g focus-events on
set-option -g renumber-windows on
# set-option -g status-right '#[fg=yellow]#H#[default]'
set-option -wg automatic-rename on # auto set-option window title
set-option -wg mode-keys vi # use vi key bindings in copy mode
set-option -wg pane-base-index 1
set-option -wg main-pane-width 50%
set-option -wg main-pane-height 50%
### tmux colors
# - black, red, green, yellow, blue, magenta, cyan, white.
# - bright colors, such as brightred, brightgreen, brightyellow, brightblue, brightmagenta, brightcyan.
# - colour0 through colour255 from the 256-color set.
# - hexadecimal RGB code like #000000, #FFFFFF, similar to HTML colors.
set-option -g copy-mode-match-style default
set-option -g copy-mode-mark-style default
set-option -g copy-mode-current-match-style default
set-option -g mode-style "bg=magenta,fg=black" # when "<c-g> s" to switch sessions and copy mode highlight
# set-option -g window-status-style "bg=white,fg=black,dim"
# set-option -g window-status-last-style "bg=red,fg=yellow"
# set-option -g window-status-current-style "bg=yellow,fg=red,bold"
set-option -g window-status-current-style "strikethrough"
set-option -g window-status-current-format '#[bg=black,fg=white]#I:#W#F#[default]'
set-option -g window-status-last-style dim
set-option -g status-left-length 20
set-option -g status-style "bg=#295535,fg=white"
set-option -g status-right "#[bg=#A6CC57,fg=black] %d %h #[bg=#295535,fg=white] %H:%M:%S #[default]"
set-option -g status-left "#[bg=#A6CC57,fg=black,dim][#S]#[default] " # this is tmux session name
# set-option -g status-right '#[bg=black,fg=white] %a %d %h #[bg=white,fg=black] %H:%M:%S#[default]'
# WEATHER='#(cat /tmp/weather.info)'
# set -g status-right "$WEATHER"
################################
## Plugins
################################
# set -g @plugin 'tmux-plugins/tpm'
# set -g @plugin 'sainnhe/tmux-fzf'
# TMUX_FZF_LAUNCH_KEY="/"
# run '~/.tmux/plugins/tpm/tpm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment