# # ~/.tmux.conf # # Tips # ---- # * With mouse mode enabled, it is not allowed to select text with mouse. # However, pressing "Shift" key while doing things with the mouse will # overrides the mouse protocol and lets you select/paste. This behavior # is documented in xterm(1) and also supported by most terminals. # Credit: https://unix.stackexchange.com/a/332425 # # Start window and pane numbering at 1 set -g base-index 1 setw -g pane-base-index 1 # Renumber the windows when a window is closed set -g renumber-windows on # Automatically set window title set -g set-titles on setw -g automatic-rename on # Don't allow programs to change the window name set -g allow-rename off # Use vi-style key bindings in the status line set -g status-keys vi # Use vi-style key bindings in copy and choice modes setw -g mode-keys vi # Disable the delay between an escape key press and subsequent characcters set -sg escape-time 0 # Increase the scrollback history limit set -g history-limit 10000 # Lock after 15 minutes #set -g lock-after-time 1800 # Keep windows around after they exit # On exit, the pane will display the message "Pane is dead" until it is # closed with the command "kill-pane" or "kill-window", or a new command # is started there with "respawn-pane" or "respawn-window". #set -g remain-on-exit on # Turn on xterm-keys so that additional function keys get escape sequences set -g xterm-keys on set -g default-terminal "tmux-256color" # Enable true (RGB) color set -sa terminal-overrides ",xterm*:Tc" # Override terminal's default Cr (color reset) to avoid the strange # 'char+112' when just exited the tmux session. # Credit: https://github.com/tmux/tmux/issues/266 set -sa terminal-overrides ',xterm*:Cr=\E]12;gray\007' ## ## Key bindings ## # Change the prefix key to C-a set -g prefix C-a unbind C-b bind C-a send-prefix # Get the command prompt more quickly unbind \; bind \; command-prompt # Detach tmux instead of exit bind -n C-d detach # Sane window split keybinds unbind '"' unbind % bind | split-window -h -c '#{pane_current_path}' bind \ split-window -h -c '#{pane_current_path}' bind - split-window -v -c '#{pane_current_path}' # Pane switching bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D # Pane resizing bind -r M-h resize-pane -L 5 bind -r M-j resize-pane -D 5 bind -r M-k resize-pane -U 5 bind -r M-l resize-pane -R 5 # Create new window starting from the current directory bind c new-window -c '#{pane_current_path}' # URxvt tab like window control bind -n S-Down new-window -c '#{pane_current_path}' bind -n S-Left previous-window bind -n S-Right next-window bind -n C-Left swap-window -t -1 bind -n C-Right swap-window -t +1 # Enable/disable mouse mode bind m set mouse\; display 'Toggled mouse #{?mouse,on,off} (this session)' bind M set -g mouse\; display 'Globally toggled mouse #{?mouse,on,off}' # Keys to toggle monitoring activity in a window, and synchronize-panes #bind m set monitor-activity bind S set synchronize-panes\; display 'synchronize-panes #{?synchronize-panes,on,off}' # Reload Tmux configuration bind R source-file ~/.tmux.conf\; display "Configuration reloaded." # Do not display the original window's name when renaming it bind , command-prompt -p "(rename-window '#W')" "rename-window '%%'" # Do the same for session renaming bind '$' command-prompt -p "(rename-session '#S')" "rename-session '%%'" # Save all scrollback to a file # Credit: https://unix.stackexchange.com/a/26568 bind P command-prompt -p 'save history to filename:' \ -I '~/tmux.history' 'capture-pane -S - ; save-buffer %1 ; delete-buffer' # Copy & paste bind Escape copy-mode bind p paste-buffer ## ## Appearance ## # Status line set -g status-justify centre set -g status-left-length 30 set -g status-right-length 30 set -g status-style "bg=default,bold" set -g status-left \ "#[fg=magenta][#[fg=yellow]#h:#[fg=blue]#S#[fg=magenta]]#[default]" set -g status-right \ "#[fg=magenta][#[fg=green]%a #[fg=yellow]%b %d #[fg=blue]%H:%M#[fg=magenta]]" # If running inside tmux ($TMUX is set), then change the status line to red #if-shell -b '[ -n "$TMUX" ]' "set -g status-bg red" # Window status setw -g window-status-separator " " setw -g window-status-style "fg=blue,bold" setw -g window-status-current-style "fg=green,bold,reverse" setw -g window-status-last-style "fg=magenta,bold" setw -g window-status-activity-style "fg=yellow,bold" setw -g window-status-bell-style "fg=red,bold" setw -g window-status-format \ "#[fg=yellow]#I:#[default]#{=10:window_name}#F" setw -g window-status-current-format \ "#[fg=yellow]#I:#[fg=default]#W#F" # Window mode setw -g mode-style "fg=yellow,bg=default,bold" setw -g clock-mode-colour green setw -g clock-mode-style 24 # Messaging set -g message-style "fg=white,bg=blue,bold" set -g message-command-style "fg=white,bg=default,bold" # Highlight windows with activity in the status line setw -g monitor-activity on # Disable bell action and activity messages set -g bell-action none set -g visual-activity off # Pane set -g pane-border-style "fg=default,bg=default" set -g pane-active-border-style "fg=blue,bg=default" ## ## Deal with different syntax between different versions! ## # Credit: https://stackoverflow.com/a/40902312/1046584 run-shell "tmux setenv -g TMUX_VERSION $(tmux -V | cut -c 6-)" # In version 2.1 "mouse" replaced the previous 4 mouse options if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.1" | bc)" = 1 ]' \ "set -g mouse on" # UTF8 is autodetected in 2.2 onwards, but errors if explicitly set if-shell -b '[ "$(echo "$TMUX_VERSION < 2.2" | bc)" = 1 ]' \ "set -g utf8 on; set -g status-utf8 on; set -g mouse-utf8 on" # New keybindings for vi-mode # Credit: https://shapeshed.com/custom-vim-bindings-in-tmux-2-4/ # See also: https://github.com/tmux/tmux/issues/754 if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.4" | bc)" = 1 ]' \ "unbind -T copy-mode-vi MouseDragEnd1Pane; \ bind -T copy-mode-vi 'v' send -X begin-selection; \ bind -T copy-mode-vi 'V' send -X select-line; \ bind -T copy-mode-vi 'r' send -X rectangle-toggle; \ bind -T copy-mode-vi 'y' send -X copy-pipe-and-cancel \ 'xclip -in -selection clipboard'" if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' \ "unbind -t vi-copy MouseDragEnd1Pane; \ bind -t vi-copy Escape cancel; \ bind -t vi-copy v begin-selection; \ bind -t vi-copy V select-line; \ bind -t vi-copy r rectangle-toggle; \ bind -t vi-copy y copy-pipe 'xclip -in -selection clipboard'" # vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=tmux: #