tmux conf

Posted by chunyang on April 11, 2022
TAGS: #tmux

TMux is really awesome when you want to run commands on servers. But due to all kinds of reasons, you may lose the connection. If you reconnect to the same session, everything magically restores.

TMux conf

# Turn off confirmation before closing actions
bind-key & kill-window
bind-key x kill-pane

set -g @yank_selection_mouse 'clipboard'

# Kill window instead of keeping the exit window
set -g remain-on-exit off

set -g default-command "${SHELL}"

bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

setw -g mode-keys vi
set -g default-terminal "xterm-256color"

set -g status-right "%H:%M"
set -g window-status-current-style "underscore"

# If running inside tmux ($TMUX is set), then change the status line to red
%if #{TMUX}
set -g status-bg red
%endif

# No bells at all
set -g bell-action none

# Turn the mouse on, but without copy mode dragging
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' 'copy-mode -e'"
# Allow xterm titles in terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right
set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"

# Scroll History
set -g history-limit 30000

# Set ability to capture on start and restore on exit window data when running an application
setw -g alternate-screen on

# Lower escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50

# TPM
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'

run '~/.tmux/plugins/tpm/tpm'

Install plugin

Use “tpm” to manage plugins

Ctrl + b + I

Shortcuts

Prefix = Ctrl + b

# window selection
c+b c # new window
c+b & # close window
c+b n/p # next or previous window

# pane selection
c+b % # split pane horizontal
c+b " # split pane vertical "
c+b x # close current pane
c+b ! # convert pane to a window
c+b left/right/up/down arrow # move focus between panes
c+b q # show pane number
c+b q + 0-9 # switch to pane by index
c+b $ # Rename session

# copy mode

c+b [ # enter copy mode
q # exit copy mode

Session

tmux ls
tmux attach -t {SessionName}

Notes

Renumber the window

# Renumber window when close or create windows
set -g renumber-windows on

Restart a pane

Prefix + :
respawn-pane -k

Notification when command exits

In zsh, put following in .zshrc

precmd () {
  echo -n -e "\a"
}

In .tmux.conf

set -g bell-action none

Copy mode

Press q to exit copy mode

Yank

  • For vim, Plug 'ojroques/vim-oscyank'

Please refer to yank related configuration for tmux.

Reference