Skip to content

Instantly share code, notes, and snippets.

@sbeam
Last active June 6, 2019 18:04
Show Gist options
  • Save sbeam/e6f625aaeb857c6c7b60 to your computer and use it in GitHub Desktop.
Save sbeam/e6f625aaeb857c6c7b60 to your computer and use it in GitHub Desktop.
# Add truecolor support{{{
set-option -sa terminal-overrides ",xterm*:Tc"
# color 256!
set -g default-terminal "screen-256color"
# }}}
# enter copy mode on any C-Up{{{
# bind -n C-Up copy-mode -eu
# }}}
# reload this file with r{{{
bind-key r source-file ~/.tmux.conf \; \
display-message "source-file done"
# }}}
# Mouse {{{
#------------------------------------------------------
# mouse to highlight and copy; to paste use prefix + ]
# http://awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/
# temporarily allow regular terminal copy mode while mouse mode is enable
# visual line: shift+mouse
# visual block: ctrl+shift+mouse <-- only works on some terminals
# visual block: ctrl+mouse <-- (while mouse mode is disable) only works on some terminals
# Use vim keybindings in copy mode
setw -g mode-keys vi
# toggle mouse on/off
# http://tangledhelix.com/blog/2012/07/16/tmux-and-mouse-mode/
bind-key m \
set-option -g mouse on \; \
display-message 'Mouse: ON'
bind-key M \
set-option -g mouse on \; \
display-message 'Mouse: OFF'
# }}}
# Copy/Paste {{{
# new
bind-key -T copy-mode-vi v send-keys -X begin-selection
# bind-key -T copy-mode-vi y send-keys -X copy-pipe "pbcopy"
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T edit-mode-vi Up send-keys -X history-up
bind-key -T edit-mode-vi Down send-keys -X history-down
#bind-key -T copy-mode-vi C-Up send-keys -X halfpage-up
#bind-key -T copy-mode-vi C-Down send-keys -X halfpage-down
bind-key -T copy-mode-vi WheelUpPane send-keys -X halfpage-up
bind-key -T copy-mode-vi WheelDownPane send-keys -X halfpage-down
# Update default binding of `Enter` to exit copy-mode
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X cancel
# old ---
# tart copy mode when scrolling up
# bind-key -n WheelUpPane copy-mode -e
# Setup 'v' to begin selection as in Vim
# bind-key -T copy-mode-vi v begin-selection
# bind-key -T copy-mode-vi y 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 copy-pipe "reattach-to-user-namespace pbcopy"
# /old
# }}}
# copy-paste fix for Sierra# {{{
# # apparently needed for copy from tmux for Sierra,
# https://github.com/tmux/tmux/issues/543
set -g default-shell $SHELL
set -g default-command "reattach-to-user-namespace -l ${SHELL}"
# }}}
# bind + to temp-soloize (zoom) window, - to go back {{{
unbind +
bind-key + \
new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
swap-pane -s tmux-zoom.0 \;\
select-window -t tmux-zoom
unbind -
bind-key - \
last-window \;\
swap-pane -s tmux-zoom.0 \;\
kill-window -t tmux-zoom
# }}}
# Switch panes/windows - basic {{{
# # Usage: "CTRL+arrow keys" (without prefix key)
# # from https://gist.github.com/spicycode
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 windows
# # usage: "SHIFT+arrow" (without prefix key)
bind -n S-Left previous-window
bind -n S-Right next-window# }}}
# 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?)(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"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# tmux waits a beat after ESC, but this does something weird in vim with the
# :TmuxNavigation. eg, a 'k' just after ESC will trigger :TmuxNavigateDown.
set -s escape-time 0
# }}}
# set color of active/inactive panes# {{{
set -g window-style 'bg=#131313'
set -g window-active-style 'bg=#00041e'
# }}}
# clear with ctrl-f{{{
bind -n C-f send-keys -R \; clear-history
# }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment