Skip to content

Instantly share code, notes, and snippets.

@chrisshroba
Created June 11, 2019 21:03
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 chrisshroba/d43c4746d813b02d5b2347f85a4021b7 to your computer and use it in GitHub Desktop.
Save chrisshroba/d43c4746d813b02d5b2347f85a4021b7 to your computer and use it in GitHub Desktop.
# Welcome to my tmux config!
# Some helpful notes to future me
# - bind is an alias of bind-key (no difference).
# - bind <key> binds the key after the prefix.
# - bind -r <key> binds the key in the root table,
# meaning no prefix is necessary.
# -
# Put Plugins first because they may define behavior
# which I want to depend on or override.
########################## Plugins ############################
# TPM is Tmux Plugin Manager. It manages installing the rest
# of the plugins.
set -g @plugin 'tmux-plugins/tpm'
# This plugin sets some sensible defaults for tmux, including:
# - binding prefix + a (or whatever key is your prefix key
# with Ctrl) to switch to the last window you were in
# - automatically reattach to user namespace, i.e. for
# clipboard interaction (copy/paste)
set -g @plugin 'tmux-plugins/tmux-sensible'
# TODO comment this
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-save-interval '1'
######################## End Plugins ##########################
# Make it so when you set the window title,
# it is never automatically changed by tmux
set-option -g allow-rename off
# This enables mouse reporting. It lets you:
# - Click on a pane to activate it
# - Right click a pane to `mark` it
# - Drag borders to resize panes
setw -g mouse on
set -g mouse on
# Remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind C-a send-prefix
# Use prefix + | to split the pane into two panes
# vertically, and prefix + - for horizontal, because
# those characters look like the result of the split.
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Unbind the old split-window keys
unbind '"'
unbind %
# Bind Prefix + " to interactive window selection, similar
# to how it works in screen
bind '"' choose-tree -w
# Bind Prefix + r to reload the tmux config on the fly
bind r source-file ~/.tmux.conf
# Switch panes using Ctrl + Arrows with no Prefix
bind -n C-Left select-pane -L
bind -n C-Right select-pane -R
bind -n C-Up select-pane -U
bind -n C-Down select-pane -D
# Switch panes using Ctrl + Vim keys with no Prefix
# bind -n C-h select-pane -L
# bind -n C-l select-pane -R
# bind -n C-k select-pane -U
# bind -n C-j select-pane -D
# Resize panes using Ctrl + Shift + Arrows with no Prefix
bind -n C-S-Left resize-pane -L
bind -n C-S-Right resize-pane -R
bind -n C-S-Up resize-pane -U
bind -n C-S-Down resize-pane -D
# CAUTION: This doesn't seem to currently work. TODO fix:
# More sane bindings for copy mode: v starts selection
# (like in vim), and y 'yanks' selection, aka putting it
# on the clipboard (both in tmux and on computer)
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Update DISPLAY env variable so that programs that launch
# in X will work (i.e. meld)
set-option -g update-environment "DISPLAY"
# TODO figure out what the next two lines are doing
# Source:
# github.com/tmux/tmux/issues/696#issuecomment-360629057
# Use the xterm-256color terminal
set -g default-terminal "xterm-256color"
# Apply Tc
set-option -ga terminal-overrides ",xterm-256color:Tc"
# Prefix + s swaps the current pane with the 'marked' pane
# (Prefix + m 'marks' a pane)
bind-key s swap-pane
# Prefix + k kills window with confirmation (just like
# Prefix + &)
bind k confirm-before -p "kill-window #W? (y/n)" kill-window
# Put tmux into vi mode. This makes copy mode use vim-like
# key bindings instead of emacs-like bindings.
set-window-option -g mode-keys vi
# Put the status bar at the top of the window instead of the\
# bottom
set-option -g status-position top
set -g base-index 1
set-option -g message-style 'fg=blue'
set-option -g message-command-style 'fg=red'
# This is some styling I like. The current pane is black, all
# inactive panes are grey, all borders are the same color grey,
# and no lines are drawn (technically they are, but in the same
# color as the background, so they're invisible).
# set-window-option -g window-active-style 'fg=default, bg=colour232'
# set-window-option -g window-style 'fg=default, bg=#222a38'
# set-window-option -g window-active-style 'fg=default, bg=#2E3440'
# set-window-option -g pane-border-style 'fg=#222a38, bg=#222a38'
# set-window-option -g pane-active-border-style 'fg=#2E3440, bg=default'
set-window-option -g window-style 'fg=default, bg=colour8'
set-window-option -g window-active-style 'fg=default, bg=colour0'
set-window-option -g pane-border-style 'fg=colour8, bg=colour8'
set-window-option -g pane-active-border-style 'fg=colour8, bg=colour8'
# set-window-option -g window-active-style 'fg=default, bg=colour232'
# set-window-option -g window-style 'fg=default, bg=default'
# set-window-option -g pane-border-style 'fg=default, bg=default'
# set-window-option -g pane-active-border-style 'fg=colour234, bg=colour234'
# Restore C-k behavior to shell default of erasing to end of line
unbind -T root C-k
# Normally, the tmux config is only read when the tmux *server*
# starts, which happens super infrequently, so this makes every
# new window use the most up-to-date version of the config.
set-hook -g after-new-window 'source ~/.tmux.conf'
# Prompt for a window name every time a new window is created,
# because manual window names are far more descriptive than the
# automatic ones.
##set-hook -g after-new-window "command-prompt -p \"Window name: \" \"rename-window '%%'\""
bind-key c new-window \; command-prompt -p "Window name: " "rename-window '%%'"
set -s 'command-alias[0]' which='display-message -p "#{window_index}.#{pane_index}"'
unbind o
bind o run tmux-url-select
# Initialize TMUX plugin manager
# This line should be kept at the end of the file.
run '~/.tmux/plugins/tpm/tpm'
source /usr/share/powerline/bindings/tmux/powerline.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment