Skip to content

Instantly share code, notes, and snippets.

@huynle
Last active June 26, 2020 07:02
Show Gist options
  • Save huynle/f874b330a5ffd7add01d88baa65636b3 to your computer and use it in GitHub Desktop.
Save huynle/f874b330a5ffd7add01d88baa65636b3 to your computer and use it in GitHub Desktop.
tmux configuration
# Use 'tmux list-keys' to see all the key bindings
#### GOOD STUFF comes from here ####
# https://github.com/gpakosz/.tmux/blob/master/.tmux.conf
# -- general -------------------------------------------------------------------
# Set Terminal colors; enable terminal compability
### This is the article you would want to be reading
# https://github.com/tmux/tmux/issues/696
set -g default-shell $SHELL
# set -g default-terminal "xterm-256color"
set -g default-terminal "screen-256color"
## make tmux display things in 256 colors
# set -g default-terminal "screen-256color"
set-option -sa terminal-overrides ",xterm-256color:RGB"
set-option -g set-titles on
set-option -g set-titles-string '#T #W tmux{#S}:#I.#P'
set-window-option -g automatic-rename on
set-window-option -g xterm-keys on
# default statusbar colors
# set -g status-fg white
set -g status-bg default
# # active window title colors
setw -g window-status-current-style bg=default,fg=red,dim
# default window title colors
setw -g window-status-style bg=default,fg=white,dim
# statusline
set -g status-justify centre # center window list for clarity
set -g status-left '#[fg=green][#H]['
set -g status-right '#[fg=green]][#[fg=blue]%Y-%m-%d #[fg=white]%I:%M#[fg=green]]'
set -g status-right-length 50
set -g status-left-length 50
# show host name and IP address on left side of status bar
# -- display -------------------------------------------------------------------
# clear both screen and history
bind-key -r C-l send-keys C-l \; run 'sleep 0.1' \; clear-history
set -g history-limit 100000
# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on
# Start windows and panes at 1, not 0
set -g base-index 0
setw -g pane-base-index 0
# setting time for tmux to wait for escape
set -s escape-time 0
# Set the repeat-time to 1 second so that multiple commands can be entered
# without sending the prefix-key within 1 second. Commands are made repeatable
# by -r option of bind-key. By default it is 500 ms.
set -g repeat-time 500
# don't rename windows automatically
set-option -g allow-rename off
set -g renumber-windows on # renumber windows when a window is closed
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
set-window-option -g aggressive-resize on
# activity
set -g monitor-activity on
set -g visual-activity off
# Key Binding
# ----------------------------------
# remap prefix from 'C-b' tc 'C-a'
# to the to bind tmux is to use `ctrl + a` similar to Vim
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# tile all windows
unbind =
bind = select-layout tiled
# Quick layout shortcuts
bind-key b set-window-option main-pane-width 90\; select-layout main-vertical
bind-key B set-window-option main-pane-height 30\; select-layout main-horizontal
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf \; display "Config Reloaded!"
# quickly open a new window
bind-key k confirm-before kill-pane
bind-key K confirm-before kill-window
bind-key x confirm-before kill-session
bind-key X confirm-before kill-server
# Use a tick for renaming the window prompt
unbind-key 'n'
bind-key n command-prompt -I '#W' -p 'Rename window>' "rename-window '%%'"
unbind-key '$'
bind-key '$' command-prompt -I '#S' -p 'Rename session>' "rename-session '%%'"
# split panes using | and -
# Use v and g for splitting from current path
unbind-key %
unbind-key '"'
bind '\' splitw -h -c "#{pane_current_path}"
bind '-' splitw -v -c "#{pane_current_path}"
# cycling through avai windows, do bind, release, then ctrl+h or ctrl+l to cycle
bind-key -r h previous-window
bind-key -r l next-window
bind Tab last-window # move to last active window
# resizing panes
bind-key -r Left resize-pane -L 5
bind-key -r Down resize-pane -D 5
bind-key -r Up resize-pane -U 5
bind-key -r Right resize-pane -R 5
# moving window left and right
bind-key -r < swap-window -t -1
bind-key -r > swap-window -t +1
# # Quick view of processes
# bind-key P split-window -h 'exec top'
# Quick view of systemlog
bind-key J split-window -h 'journalctl -f'
# Help screen: rebind list-keys window into a new pane
bind-key ? split-window -h 'exec tmux list-keys | less'
# Disable Ctrl+Arrows to maintain word jump
unbind-key -n C-Left
unbind-key -n C-Right
unbind-key -n C-Up
unbind-key -n C-Down
# -- Control Options -----------------------------------------------------------
# bind vi key-mapping
set-option -g status-keys vi
# vi-style controls for copy mode
set-window-option -g mode-keys vi
# -- copy mode -----------------------------------------------------------------
bind Enter copy-mode # enter copy mode
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'cat > ~/.vbuf'
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "cat > ~/.vbuf"
# -- buffers -------------------------------------------------------------------
bind b list-buffers # list paste buffers
bind P choose-buffer # choose which buffer to paste from
bind p run-shell "cat ~/.vbuf | tmux load-buffer - ; tmux paste-buffer"
# bind p paste-buffer # paste from the top paste buffer
# -- statusline ----------------
##############################
### Color & Style Settings ###
##############################
# set -g pane-border-style fg=magenta
# set -g pane-active-border-style bg=default
# set -g pane-active-border-style fg=magenta
#
# sourcing tmuxline colors
# source ~/.dotfiles/terminals/tmux/tmuxline.conf
# source ~/.dotfiles/terminals/tmux/rafi.sh
# source ~/.dotfiles/terminals/tmux/rafi-light.sh
# source ~/.dotfiles/terminals/tmux/theme.sh
# source ~/.tmux/themes/default.sh
### allow for vim movement
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?|emacs(client)?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
# set -g default-command ' \
# function renamePane ()e{ \
# read -p "Enter Pane Name: " pane_name; \
# printf "\033]2;%s\033\\r:r" "${pane_name}"; \
# }; \
# export -f renamePane; \
# bash -i'
set -g pane-border-status bottom
# set -g pane-border-format "#{pane_index} #T #{pane_current_command}"
# bind-key -T prefix m send-keys "renamePane" C-m
# toggle pane title visibility
# bind T run 'bash -c "arr=( off top ) && tmux setw pane-border-status \${arr[\$(( \${arr[(I)#{pane-border-status}]} % 2 + 1 ))]}"'
# rename pane
# bind t command-prompt -p "(rename-pane)" -I "#T" "select-pane -T '%%'"
unbind t
bind t command-prompt -p "(rename-pane)" -I "#T" "select-pane -T '%%'"
run-shell ~/.tmux/tmux-yank/yank.tmux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment