Skip to content

Instantly share code, notes, and snippets.

@dingmingxin
Created July 16, 2016 01:17
Show Gist options
  • Save dingmingxin/ffbc811bdc06ba448c790ba8c9ba126f to your computer and use it in GitHub Desktop.
Save dingmingxin/ffbc811bdc06ba448c790ba8c9ba126f to your computer and use it in GitHub Desktop.
dmx-tmux.conf
# -- general -------------------------------------------------------------------
set -g default-terminal "xterm-256color" # colors!
set-option -g default-shell /bin/zsh
setw -g xterm-keys off
set -s escape-time 0 # fastest command sequences
set -sg repeat-time 600 # increase repeat timeout
set -s quiet on # disable various messages
unbind C-b
set -g prefix M-s
unbind \;
# uncomment to force vi-style key bindings
set -g status-keys vi
setw -g mode-keys vi
set -g history-limit 5000 # boost history
# edit configuration
bind e new-window -n '~/.tmux.conf' '${EDITOR:-vim} ~/.tmux.conf && tmux source ~/.tmux.conf && tmux display "~/.tmux.conf sourced"'
set -g mouse on
# reload configuration
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
bind z confirm-before -p "kill-session #S ? (y/n)" kill-session
# see https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
if 'which -s reattach-to-user-namespace' 'set -g default-command "tmux rename-window initializing; tmux set -w automatic-rename; reattach-to-user-namespace $SHELL -l"'
set-option -g default-command "reattach-to-user-namespace -l zsh"
# -- display -------------------------------------------------------------------
set -g base-index 1 # start windows numbering at 1
setw -g pane-base-index 1 # make pane numbering consistent with windows
#setw -g automatic-rename on # rename window to reflect current program
# renumber windows when a window is closed
set -g renumber-windows on
set -g set-titles on # set terminal title
set -g set-titles-string '#h ❐ #S ● #I #W'
set -g display-panes-time 800 # slightly longer pane indicators display time
set -g display-time 1000 # slightly longer status messages display time
set -g status-interval 10 # redraw status line every 10 seconds
# 24 hour clock
setw -g clock-mode-style 24
# clear both screen and history
bind -n C-l send-keys C-l \; run 'tmux clear-history'
# activity
set -g monitor-activity on
set -g visual-activity off
# tmux theme, colors and status line
# available themes:
# - powerline (a powerline inspired theme)
# - powerline_patched_font (a powerline inspired theme using a patched font)
tmux_conf_theme=powerline_patched_font
# -- navigation ----------------------------------------------------------------
# create new session
bind C-c new-session
# find session
bind C-f command-prompt -p find-session 'switch-client -t %%'
# pane navigation
bind h run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -L) \
|| (tmux resize-pane -Z && tmux select-pane -L)"
bind j run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -D) \
|| (tmux resize-pane -Z && tmux select-pane -D)"
bind k run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -U) \
|| (tmux resize-pane -Z && tmux select-pane -U)"
bind l run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -R) \
|| (tmux resize-pane -Z && tmux select-pane -R)"
bind H run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -L) \
|| (tmux resize-pane -Z && tmux select-pane -L && tmux resize-pane -Z)"
bind J run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -D) \
|| (tmux resize-pane -Z && tmux select-pane -D && tmux resize-pane -Z)"
bind K run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -U) \
|| (tmux resize-pane -Z && tmux select-pane -U && tmux resize-pane -Z)"
bind L run "(tmux list-panes -F '#{window_zoomed_flag}'|grep 0 > /dev/null && tmux select-pane -R) \
|| (tmux resize-pane -Z && tmux select-pane -R && tmux resize-pane -Z)"
bind > swap-pane -D # swap current pane with the next one
bind < swap-pane -U # swap current pane with the previous one
# maximize current pane
#bind + run 'cut -c3- ~/.tmux.conf | sh -s maximize_pane'
#bind + run 'cut -c3- ~/.tmux.conf | sh -s circled_digit 19'
# pane resizing
bind -n M-[ resize-pane -L 5
bind -n M-] resize-pane -R 5
bind -n M-_ resize-pane -D 5
bind -n M-+ resize-pane -U 5
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
bind s choose-tree
# vim interaction
# 当发现pane中有vim运行的时候,会将c-h/j/k/l 发送给vim
#bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-h) || ( tmux select-pane -L && ~/bin/changeInputSource 'com.apple.keylayout.US' ) "
#bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-j) || ( tmux select-pane -D && changeInputSource 'com.apple.keylayout.US' )"
#bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-k) || ( tmux select-pane -U && changeInputSource 'com.apple.keylayout.US' )"
#bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-l) || ( tmux select-pane -R && changeInputSource 'com.apple.keylayout.US' )"
#bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys 'C-\\') || ( tmux select-pane -l && changeInputSource 'com.apple.keylayout.US' ) "
bind S run -b "source ~/.zprofile"
#bind C-e command-prompt -p "session?,message?" "run-shell \"tmux list-windows -t %1 \| cut -d: -f1\|xargs -I\{\} tmux send-keys -t %1:\{\} %2\""
#bind E command-prompt -p "Command to all panes/windows/sessions:" \
#"run \"tmux list-sessions -F '##{session_name}' | xargs -I SESS \
#tmux list-windows -t SESS -F 'SESS:##{window_index}' | xargs -I SESS_WIN \
#tmux list-panes -t SESS_WIN -F 'SESS_WIN.##{pane_index}' | xargs -I SESS_WIN_PANE \
#tmux send-keys -t SESS_WIN_PANE '%1' Enter\""
# window navigation
bind -r p previous-window # select previous window
bind -r n next-window # select next window
bind space resize-pane -Z # move to last active window
## toggle mouse
bind m run "cut -c3- ~/.tmux.conf | sh -s toggle_mouse"
# -- list choice ---------------------------------------------------------------
bind -t vi-choice h tree-collapse
bind -t vi-choice l tree-expand
run 'tmux bind -t vi-choice K start-of-list 2> /dev/null'
run 'tmux bind -t vi-choice J end-of-list 2> /dev/null'
bind -t vi-choice H tree-collapse-all
bind -t vi-choice L tree-expand-all
bind -t vi-choice Escape cancel
# -- edit mode -----------------------------------------------------------------
# the following vi-copy bindings match my vim settings
# see https://github.com/gpakosz/.vim.git
bind -ct vi-edit H start-of-line
bind -ct vi-edit L end-of-line
bind -ct vi-edit q cancel
bind -ct vi-edit Escape cancel
# -- copy mode -----------------------------------------------------------------
#bind Enter copy-mode # enter copy mode
#bind b list-buffers # list paster buffers
#bind p paste-buffer # paste from the top pate buffer
#bind P choose-buffer # choose which buffer to paste from
# the following vi-copy bindings match my vim settings
# see https://github.com/gpakosz/.vim.git
bind -t vi-copy v begin-selection
bind -t vi-copy C-v rectangle-toggle
#bind -t vi-copy Escape cancel
bind -t vi-copy H start-of-line
bind -t vi-copy L end-of-line
# -- window split -----
unbind %
bind \ split-window -h
bind - split-window -v
unbind-key /
#bind-key / display-panes \; select-pane -t :.
#bind-key / command-prompt "select-pane -t '%%'"
#bind-key H select-layout even-horizontal
#bind-key V select-layout even-vertical
# copy to Mac OSX pasteboard
if 'which reattach-to-user-namespace' 'bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"'
if 'which reattach-to-user-namespace' 'bind -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"'
#=========fzf tmux========
bind-key 0 run "tmux split-window -p 40 'zsh -ci ftpane'"
# -- user defined --------------------------------------------------------------
if '[ -f ~/.tmux.conf.local ]' 'source ~/.tmux.conf.local'
# -- 8< ------------------------------------------------------------------------
run 'cut -c3- ~/.tmux.conf.customsh | sh -s apply_theme $tmux_conf_theme'
run 'for name in $(printenv | grep -Eo ^tmux_conf_[^=]+); do tmux setenv -gu $name; done;'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-sidebar'
run '~/.tmux/plugins/tpm/tpm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment