Skip to content

Instantly share code, notes, and snippets.

@venkywonka
Created December 1, 2020 05:21
Show Gist options
  • Select an option

  • Save venkywonka/b8cfa85a9f046f5018b59afbbe5ca594 to your computer and use it in GitHub Desktop.

Select an option

Save venkywonka/b8cfa85a9f046f5018b59afbbe5ca594 to your computer and use it in GitHub Desktop.
My tmux configuration dotfile
# Changes to this file aren't read by tmux automatically,
# compleletely close the tmux sesssion and reopen it or
# ~PREFIX :~ to open command mode and type "source-file ~/.tmux.conf" or
# "tsr" in terminal which is an alias in ~/.fishrc or use binding `M-f r` to make it work
#
# from FAQ file in tmux source code:
# to see the default session options by starting a new tmux server with no configuration file:
# $ tmux -Lfoo -f/dev/null start\; show -g
# Or the default window options:
# $ tmux -Lfoo -f/dev/null start\; show -gw
# setting default shell
set-option -g default-shell "/bin/bash"
# solve the arrows mess when using vim in tmux
# set -g default-terminal "xterm-256color"
set -s default-terminal "screen-256color"
# set -s terminal-overrides "*256col*:colors=256,xterm*:XT,xterm-termite:Tc"
# setw -g xterm-keys on
# use mouse to scroll the output page instead of the command history
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
# fix the konsole/yakuake bug github#933
set -as terminal-overrides ',*:indn@'
# set the prefix from C-b to M-f
set -g prefix M-f
# reload the file using Prefix-r
bind r source-file ~/.tmux.conf \; display "~/.tmux.conf reloaded!"
# switch pane, default is with -r (repeated without prefix)
bind Up select-pane -U
bind k select-pane -U
bind Down select-pane -D
bind j select-pane -D
bind Left select-pane -L
bind h select-pane -L
bind Right select-pane -R
bind l select-pane -R
bind = select-layout -E
bind + select-layout tiled
# choose the right pane using prefix-M-Num
bind 1 select-pane -t 1
bind 2 select-pane -t 2
bind 3 select-pane -t 3
bind 4 select-pane -t 4
bind 5 select-pane -t 5
bind 6 select-pane -t 6
# choose the right window using prefix-M-Num
# The default is prefix+Num
bind M-1 select-window -t :=1
bind M-2 select-window -t :=2
bind M-3 select-window -t :=3
bind M-4 select-window -t :=4
bind M-5 select-window -t :=5
bind M-6 select-window -t :=6
bind M-7 select-window -t :=7
bind M-8 select-window -t :=8
bind M-9 select-window -t :=9
# use M-f M-f to switch to last window
bind M-f last-window
# M-f t to kill-pane
bind -r t kill-pane \; set -u pane-active-border-style
# kill all other panes but the current one
bind T confirm-before "kill-pane -a"
# kill current window
#bind -r x kill-window
# kill all the other windows but the current one
bind X confirm-before "kill-window -a"
# kill tmux server and clients and destory all sessions
bind Q confirm-before "kill-server"
# Start Window Numbering at 1
set -g base-index 1
setw -g pane-base-index 1
# Aggressive resize(don't know what this means)
setw -g aggressive-resize on
# prevoius/next-window
bind -r M-x previous-window
bind -r M-v next-window
bind -r Tab next-window
# bind -r C-Tab previous-window
# or
# bind -r M-x select-window -t :-
# bind -r M-v select-window -t :+
# Vertial split-window from current dir
bind -r v split-window -p 50 -h -c "#{pane_current_path}" \; set -u pane-active-border-style
bind -r '\' split-window -p 50 -h -c "#{pane_current_path}" \; set -u pane-active-border-style
# Horizontal split-window from current dir
bind -r h split-window -p 50 -c "#{pane_current_path}" \; set -u pane-active-border-style
bind -r - split-window -p 50 -c "#{pane_current_path}" \; set -u pane-active-border-style
# create new window #from the current dir
bind c new-window # -c "#{pane_current_path}"
# copy the text in terminal using the following method:(not need to go into the copy mode first)
# hold Shift and using touchpad/mouse tmux kill-pane -aselect the text you want
# press C-S-c at the same time to copy, the text will be filled into the X clipboard
# C-S-v to paste
# copy/paste between system clipboard and tmux
# When in mouse mode, Shift-mouse to copy on select
set -g mouse on
# toggle mouse on/off
bind m set -g mouse
# prefix+[ first, select the content with mouse(hold) and then copy using M-w,
# paste using C-y, using prefix+[ will also solve the problem that
# selecting multiple lines with mouse selects contents cross panes.
# To copy:
#bind-key -n -t emacs-copy M-w copy-pipe "xclip -i -sel p -f | xclip -i -sel c "
bind-key -n -Tcopy-mode M-w send -X copy-pipe "xclip -i -sel p -f | xclip -i -sel c "\; display-message "Copied"
# To paste:
bind-key -n C-y run "xclip -o | tmux load-buffer - ; tmux paste-buffer"
set-window-option -g mode-keys vi
bind M-s copy-mode
bind-key -T copy-mode M-a send-keys -X page-up
bind-key -T copy-mode M-z send-keys -X page-down
# scrollback limit
#set-option -g history-limit 30000
set -g history-limit 30000
# Lower escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50
# Reduce the command delay time to something a bit shorter
#set -sg escape-time 1
# Extend the repeat interval for repeatable commands (e.g., resize-pane)
#set -sg repeat-time 500
# how long to show pane numbers when pressing M-f q
set -g display-panes-time 2000 # (which is 2sec)
# Automatically set window title to reflect the current program
setw -g automatic-rename on
# setw -g automatic-rename-format '{#T}'
# renumber the windows if any of them is closed
#set -g renumber-windows on
# disable M-f C-z to suspend tmux
unbind-key C-z
# disable C-d to exit shell, this C-d happens when being first input to prompt
unbind-key C-d
# clear screen
#bind -n C-l send-keys 'C-l'
#unbind-key C-l
#bind -n C-l send-keys 'C-l'
# network speed in status line, ~/.local/bin/net-speed.sh
# set update frequencey (default 15 seconds)
set -g status-interval 1
#set -g status-left '#(net-speed.sh wlp5s0)#[default]'
# Set status bar
set -g status-bg green # default->transparent
set -g status-fg black # green
set -g status-left "[#S#I#P:#{pane_height}x#{pane_width}] "
set -g status-right-length 200
set -g status-left-length 100
set -g pane-border-status top
set -g pane-border-format "#[reverse,bold]#(echo '#')#{pane_index}: #{s|$HOME|~|:pane_current_path}#[default] #(~/.local/bin/gitmux -timeout 2s #{pane_current_path})#[default]"
# use prefix+z to max/restore the current pane
# prefix+M-z to max the other one, unzoomed the window if it is already zoomed
# hit again or prefix-left/right/down/up to unzoom
bind z if-shell "[[ #{window_panes} -eq 1 || #{window_zoomed_flag} -eq 1 ]]" "resize-pane -Z ; set-option pane-active-border-style fg=green,bold" "resize-pane -Z ; set-option pane-active-border-style fg=green,bold,italics"
bind M-z if-shell "[[ #{window_panes} -eq 1 || #{window_zoomed_flag} -eq 1 ]" "resize-pane -Z; set-option pane-active-border-style fg=green,bold" "last-pane ; resize-pane -Z; set-option pane-active-border-style fg=green,bold,italics"
# set -g pane-active-border-style '#{?window_zoomed_flag,#[fg=green,bold,italics],#[fg=red,bold]}'
if-shell "[[ #{window_zoomed_flag} -eq 1 ]]" "set -g pane-active-border-style fg=green,bold,italics" "set -g pane-active-border-style fg=black,bg=yellow"
# Highlight active window
setw -g window-status-current-style fg=green,bg=black
# indentify activity in other windows
setw -g monitor-activity off
set -g visual-activity off
#setw -g window-status-activity-style bold,reverse,underscore
#setw -g window-status-format "[#I#([ #{window_panes} -gt 1 ] && echo :#{window_panes})]:#{pane_current_command}#F"
set -g window-status-format '#[fg=black]#I'
set -g window-status-current-format '#[bg=black]#I:#[bg=default]#[fg=green][#W]#[fg=yellow]#(pwd="#{pane_current_path}"; echo ${pwd####*/})#F'
# bind s list-panes -a -F '#S:#I:#P-#{pane_height}x#{pane_width} "#{pane_title}" #{history_size}'
# hiden and restore a pane
# https://unix.stackexchange.com/a/506103/130234
bind Z break-pane -d -n _hidden_pane
bind ! join-pane -s $.1
#bind w choose-tree -u
#bind w choose-tree -u -W '#{window_index}(#{window_panes}): #{window_name} #{session_attached,yes,} #{pane_current_path} #F'
#bind w choose-tree '#{window_index}(#{window_panes}): #{window_name} #{session_attached,yes,} #{pane_current_path} #F'
# bind w choose-tree
# default format of choose-tree
# bind w choose-tree -F '#{?pane_format, #{pane_current_command} "#{pane_title}",#{?window_format,#{window_name}#{window_flags} (#{window_panes} panes)#{?#{==:#{window_panes},1}, "#{pane_title}",},#{session_windows} windows#{?session_grouped, (group ,}#{session_group}#{?session_grouped,),}#{?session_attached, (attached),}}}'
bind w choose-tree -F '#{?pane_format, <#[fg=green]#{pane_tty}>#[default] #[fg=red]#{pane_current_command}#[default] "#{pane_title}",#{?window_format,#{window_name}#{window_flags} (#{window_panes} panes)#{?#{==:#{window_panes},1}, #[fg=black]"<#{pane_tty}>#[default] #{pane_title}",},#{session_windows} windows#{?session_grouped, (group ,}#{session_group}#{?session_grouped,),}#{?session_attached, (attached),}}}'
set -g message-style fg=red,bg=default,bright
#set -g display-time 3000
# scroll the screen of the other pane from the current pane
bind -r M-PageDown last-pane \; send-keys "PageDown" \; last-pane
bind -r M-PageUp last-pane \; send-keys "PageUp" \; last-pane
bind -r M-Home last-pane \; send-keys "Up" \; last-pane
bind -r M-End last-pane \; send-keys "Down" \; last-pane
# default is 5 at the end, set them to C-Up/Down/Left/Right since prefix is M-f
bind -r M-Up resize-pane -U 2
bind -r M-Down resize-pane -D 2
bind -r M-Left resize-pane -L 2
bind -r M-Right resize-pane -R 2
# IC/DC = Insert/Delete
bind-key -r IC resize-pane -U 5
bind-key -r DC resize-pane -D 5
bind-key -r Home resize-pane -L 5
bind-key -r End resize-pane -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment