dotfiles/.tmux.conf

106 lines
4.1 KiB
Plaintext

unbind r
bind r source-file ~/.tmux.conf
unbind C-b
set -g prefix C-s
bind C-s send-prefix
bind C-w send-keys C-w
# Create new session
bind C new-session
# Kill session
bind X confirm-before -p "kill-session #S? (y/n)" kill-session
# More intuitive split commands
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
set -g mouse on
# act like vim
setw -g mode-keys vi
set -g focus-events on
# Start windows and panes at 1, not 0
set -g base-index 1
set -g pane-base-index 1
# Renumber windows when a window is closed
set -g renumber-windows on
set -g set-clipboard on
# Status Line
set-option -g status-position top
set -g status-bg black
set -g status-fg white
set -g status-left-length 0
set -g status-right-length 0
set -g pane-border-style fg=brightblack
set -g pane-active-border-style fg=yellow
set -g message-style bg=yellow,fg=black,bold
# Background color logic
bg_color="#{?#{==:#{client_key_table},VIMLIKE},brightmagenta,#{?client_prefix,brightblue,yellow}}"
# Text logic
status_text="#{?#{==:#{client_key_table},VIMLIKE}, WINDOW,#{?client_prefix, PREFIX, NORMAL}}"
# Left side - yellow section with session, transition to gray
set -g status-left "#[fg=black,bg=${bg_color},bold]${status_text} #[fg=black,bg=white] #S "
# Right side
set -g status-right "#(whoami)@#h #{?client_utf8,| utf-8,} #[fg=black,bg=white] %I:%M %p | %b %d #[fg=black,bg=${bg_color}] #I:#P "
# Window list in the gray middle section
set -g window-status-format " #I #W "
set -g window-status-current-format "#[fg=${bg_color},bg=black,bold][#I #W]"
set -g window-status-separator ""
# Smart pane switching with awareness of Vim splits
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
# Ctrl-w prefix
bind -n C-w switch-client -T VIMLIKE
# Navigation that works with both tmux and vim
bind -T VIMLIKE C-h if-shell "$is_vim" 'send-keys C-w C-h' 'select-pane -L'
bind -T VIMLIKE C-j if-shell "$is_vim" 'send-keys C-w C-j' 'select-pane -D'
bind -T VIMLIKE C-k if-shell "$is_vim" 'send-keys C-w C-k' 'select-pane -U'
bind -T VIMLIKE C-l if-shell "$is_vim" 'send-keys C-w C-l' 'select-pane -R'
bind -T VIMLIKE h if-shell "$is_vim" 'send-keys C-w h' 'select-pane -L'
bind -T VIMLIKE j if-shell "$is_vim" 'send-keys C-w j' 'select-pane -D'
bind -T VIMLIKE k if-shell "$is_vim" 'send-keys C-w k' 'select-pane -U'
bind -T VIMLIKE l if-shell "$is_vim" 'send-keys C-w l' 'select-pane -R'
bind -T VIMLIKE Left if-shell "$is_vim" 'send-keys C-w Left' 'select-pane -L'
bind -T VIMLIKE Down if-shell "$is_vim" 'send-keys C-w Down' 'select-pane -D'
bind -T VIMLIKE Up if-shell "$is_vim" 'send-keys C-w Up' 'select-pane -U'
bind -T VIMLIKE Right if-shell "$is_vim" 'send-keys C-w Right' 'select-pane -R'
# Window management
bind -T VIMLIKE v if-shell "$is_vim" 'send-keys C-w v' 'split-window -h -c "#{pane_current_path}"' # vertical split
bind -T VIMLIKE s if-shell "$is_vim" 'send-keys C-w s' 'split-window -v -c "#{pane_current_path}"' # horizontal split
bind -T VIMLIKE c if-shell "$is_vim" 'send-keys C-w c' 'new-window -c "#{pane_current_path}"' # new window
bind -T VIMLIKE q if-shell "$is_vim" 'send-keys C-w q' 'kill-pane' # close pane
bind -T VIMLIKE o if-shell "$is_vim" 'send-keys C-w o' 'kill-pane -a' # only this pane
# Resizing
bind -T VIMLIKE + if-shell "$is_vim" 'send-keys C-w +' 'resize-pane -U 5'
bind -T VIMLIKE - if-shell "$is_vim" 'send-keys C-w -' 'resize-pane -D 5'
bind -T VIMLIKE < if-shell "$is_vim" 'send-keys C-w <' 'resize-pane -L 5'
bind -T VIMLIKE > if-shell "$is_vim" 'send-keys C-w >' 'resize-pane -R 5'
bind -T VIMLIKE = if-shell "$is_vim" 'send-keys C-w =' 'select-layout even-horizontal'
# Movement between windows
bind -T VIMLIKE C-w if-shell "$is_vim" 'send-keys C-w C-w' 'last-window' # Ctrl-w Ctrl-w
bind -T VIMLIKE w if-shell "$is_vim" 'send-keys C-w w' 'last-window' # Ctrl-w w
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'