Skip to content

Instantly share code, notes, and snippets.

@babakness
Created March 17, 2020 20:47
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 babakness/6e1378645fa2922c3da3a20213abeed7 to your computer and use it in GitHub Desktop.
Save babakness/6e1378645fa2922c3da3a20213abeed7 to your computer and use it in GitHub Desktop.
My Tmux
# Use C-Space instead of C-b for tmux. C-Space C-Space to get "C-Space".
set-option -g default-shell /usr/local/bin/fish
set-option -g history-limit 100000
unbind-key C-b
set -g prefix C-Space
bind-key C-Space send-prefix
# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"
# force true colour on:
set -ga terminal-overrides ",xterm-256color:Tc"
# Use reattach-to-user-namespace if it's available
#set -g default-command "command -v reattach-to-user-namespace > /dev/null && reattach-to-user-namespace -l $SHELL || $SHELL -l"
# Lower key repeat rate (default: 500ms)
set -g repeat-time 125
# Don't wait for escape sequences:
set -s escape-time 0
# Show messages for 1 second:
set -g display-time 1000
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"
# Start windows and panes at 1, not 0
set -g base-index 1
set -g pane-base-index 1
set -g renumber-windows on
# <Shift>-<Left/Right> to swap windows:
bind -n S-Left previous-window
bind -n S-Right next-window
# <Ctrl><Shift>-<Left/Right> to reorder windows:
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
# Reload:
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
# Enable mouse events:
set -g mouse on
# When scrolling up in normal mode, automatically select that pane,
# and enter copy mode (exiting again on scroll to bottom):
bind-key -n WheelUpPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind-key -n WheelDownPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; send-keys -M"
# When scrolling in `vi-copy` mode, the scroll one line at a time:
bind-key -T copy-mode-vi WheelUpPane send-keys -X scroll-up
bind-key -T copy-mode-vi WheelDownPane send-keys -X scroll-down
# New panes should start in the current directory:
bind '-' split-window -c "#{pane_current_path}"
bind '/' split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
# Smart pane switching with awareness of vim splits.
# See https://github.com/neovim/neovim/issues/2048 for fix for <C-h> not working
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h ) || tmux select-pane -L || tmux select-pane"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j ) || tmux select-pane -D || tmux select-pane"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k ) || tmux select-pane -U || tmux select-pane"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l ) || tmux select-pane -R || tmux select-pane"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"
# Ensure "clear screen" is still accessible with the prefix:
bind C-l send-keys 'C-l'
bind C-k clear-history
## status bar
set -g status-bg "#191919"
set -g status-justify 'centre'
# left
set -g status-left-fg "#918175"
set -g status-left-bg "#191919"
set -g status-left ' #(hostname -s): #S '
set -g status-left-length '100'
# right
set -g status-right-fg "#918175"
set -g status-right-bg "#191919"
set -g status-right ' %H:%M '
set -g status-right-length '100'
## window options
# colour
set -g window-status-fg "#555555"
set -g window-status-bg "#191919"
set -g window-status-format ' #I #W '
set -g window-status-current-fg "#999999"
set -g window-status-current-bg "#000000"
set -g window-status-current-format ' #I #W '
## pane options
# colour
set -g pane-border-fg "#191919"
set -g pane-border-bg "#000000"
set -g pane-active-border-fg "#918175"
set -g pane-active-border-bg "#000000"
## message options
# colour
set -g message-fg colour0
set -g message-bg colour202
#set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
#
## Copy-paste integration
#set-option -g default-command "reattach-to-user-namespace -l /usr/local/bin/fish"
#
## Use vim keybindings in copy mode
#setw -g mode-keys vi
#
## Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send-keys -X begin-selection
#bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "bash -c 'tee >(nc -w0 localhost 8378) >(nc -w0 localhost 8377)' "
#
## Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
#bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "bash -c 'tee >(nc -w0 localhost 8378) >(nc -w0 localhost 8377)' "
#
## Bind ']' to use pbpaste
#bind ] run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"
#
## Bind prefix-M-w to copy-selection, save selection to buffer, and then pipe it's contents to pbcopy
bind M-w send-keys c\;\
# save-buffer /tmp/tmux-buffer\;\
# run-shell "reattach-to-user-namespace -l bash -c 'cat /tmp/tmux-buffer|pbcopy'"
#
setw -g mode-keys vi
#bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection
#bind-key -T copy-mode-emacs MouseDragEnd1Pane send-keys -X copy-selection
#bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "bash -c 'tee >(nc -w0 localhost 8378) >(nc -w0 localhost 8377)' "
bind-key -T prefix C-z suspend-client
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
#bind -n S-Pageup if-shell "$is_vim" "send-keys Pageup" "copy-mode -u"
set-option -g default-shell /usr/local/bin/fish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment