dotfiles/home/user/.config/tmux/mappings.conf

191 lines
5.9 KiB
Plaintext

# vim: ft=tmux
set -g prefix C-b
bind C-b send-prefix
# Toggle local tmux mappings to allow control remote tmux
bind -T root F12 \
set prefix None \;\
set key-table off \;\
set status off
bind -T off F12 \
set -u prefix \;\
set -u key-table \;\
set status on
## Toggle remote tmux mappings
bind F12 send-keys F12
# Choose session with key index starting from 1
bind s choose-tree -ZsK '#{?#{e|<:#{line},9},#{e|+:1,#{line}},#{?#{e|<:#{line},35},M-#{a:#{e|+:97,#{e|-:#{line},9}}},}}'
# Switch new session
bind n new-session -c ~
# Switch new named session
bind N command-prompt -p "New session:" "new-session -A -s '%1' -c ~"
# Kill session
bind x confirm-before -p "kill current session? (y/n)" "kill-session"
# Kill last session
bind X confirm-before -p "kill last session [#{client_last_session}]? (y/n)" "kill-session -t #{client_last_session} \; display-message \"Killed last session\""
# Kill other sessions
bind C-x confirm-before -p "kill other sessions? (y/n)" "kill-session -a"
# kill pane
bind q confirm-before -p "kill current pane? (y/n)" "kill-pane"
# kill window
bind Q confirm-before -p "kill current window? (y/n)" "kill-window"
# Kill other windows
bind C-q confirm-before -p "kill other windows? (y/n)" "kill-window -a"
bind r command-prompt -I '#W' -p "New window name:" "rename-window '%%'"
bind R command-prompt -I '#S' -p "New session name:" "rename-session '%%'"
# SSH Session
bind h command-prompt -p "Remote host:" "new-session -n 1 -s 'ssh-%1' -A ssh %1"
# Call prompt via prefix ;
bind ';' command-prompt
# Zoom pane
bind -n M-f resize-pane -Z
# Link window
bind L command-prompt -p "Link window from (session:window):" "link-window -s %% -a"
# Join pane
bind J choose-window -Z 'join-pane -s "%%"'
# Lock screen
bind l confirm-before -p "lock tmux? (y/n)" lock-session
# Reload config
bind F5 reload-config
# Panes navigation
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-j select-pane -D
bind -n M-k select-pane -U
# Sync panes
bind o if -F '#{pane_synchronized}' 'setw synchronize-panes off' 'setw synchronize-panes on'
bind O setw synchronize-panes off
# Detach
bind D if -F '#{session_many_attached}' \
'confirm-before -p "Detach other clients? (y/n)" "detach -a"' \
'display "Session has only 1 client attached"'
bind i display-message \; display-panes
# Windows navigation
bind -n M-p previous-window
bind -n M-n next-window
bind -n M-Tab last-window
bind -n M-1 if-shell 'tmux select-window -t 1' '' 'new-window -t 1 -n 1 -c "#{pane_current_path}"'
bind -n M-2 if-shell 'tmux select-window -t 2' '' 'new-window -t 2 -n 2 -c "#{pane_current_path}"'
bind -n M-3 if-shell 'tmux select-window -t 3' '' 'new-window -t 3 -n 3 -c "#{pane_current_path}"'
bind -n M-4 if-shell 'tmux select-window -t 4' '' 'new-window -t 4 -n 4 -c "#{pane_current_path}"'
bind -n M-5 if-shell 'tmux select-window -t 5' '' 'new-window -t 5 -n 5 -c "#{pane_current_path}"'
bind -n M-6 if-shell 'tmux select-window -t 6' '' 'new-window -t 6 -n 6 -c "#{pane_current_path}"'
bind -n M-7 if-shell 'tmux select-window -t 7' '' 'new-window -t 7 -n 7 -c "#{pane_current_path}"'
bind -n M-8 if-shell 'tmux select-window -t 8' '' 'new-window -t 8 -n 8 -c "#{pane_current_path}"'
bind -n M-9 if-shell 'tmux select-window -t 9' '' 'new-window -t 9 -n 9 -c "#{pane_current_path}"'
bind -n M-0 if-shell 'tmux select-window -t 10' '' 'new-window -t 10 -n 10 -c "#{pane_current_path}"'
# Moving pane to window by Alt+Shift+Number
bind -n 'M-!' if-shell 'tmux join-pane -d -h -t :1' '' 'break-pane -t 1 -d -n 1'
bind -n 'M-@' if-shell 'tmux join-pane -d -h -t :2' '' 'break-pane -t 2 -d -n 2'
bind -n 'M-#' if-shell 'tmux join-pane -d -h -t :3' '' 'break-pane -t 3 -d -n 3'
bind -n 'M-$' if-shell 'tmux join-pane -d -h -t :4' '' 'break-pane -t 4 -d -n 4'
bind -n 'M-%' if-shell 'tmux join-pane -d -h -t :5' '' 'break-pane -t 5 -d -n 5'
bind -n 'M-^' if-shell 'tmux join-pane -d -h -t :6' '' 'break-pane -t 6 -d -n 6'
bind -n 'M-&' if-shell 'tmux join-pane -d -h -t :7' '' 'break-pane -t 7 -d -n 7'
bind -n 'M-*' if-shell 'tmux join-pane -d -h -t :8' '' 'break-pane -t 8 -d -n 8'
bind -n 'M-(' if-shell 'tmux join-pane -d -h -t :9' '' 'break-pane -t 9 -d -n 9'
bind -n 'M-)' if-shell 'tmux join-pane -d -h -t :10' '' 'break-pane -t 10 -d -n 10'
# Swapping windows
bind -r "<" swap-window -d -t -1
bind -r ">" swap-window -d -t +1
# Windows splitting
bind -n M-Enter split-window -h -l 37% -c "#{pane_current_path}"
bind -n M-t split-window -v -l 20% -c "#{pane_current_path}"
bind \\ split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Resizing
bind -n C-M-l resize-pane -R
bind -n C-M-h resize-pane -L
bind -n C-M-j resize-pane -D
bind -n C-M-k resize-pane -U
# Swappings panes
bind -n M-L swap-pane -d -t '{left-of}'
bind -n M-H swap-pane -d -t '{right-of}'
bind -n M-J swap-pane -d -t '{down-of}'
bind -n M-K swap-pane -d -t '{up-of}'
# Copy mode
setw -g mode-keys vi
bind v copy-mode
bind -r p paste-buffer
bind C-p choose-buffer
## Toggle selection
bind -T copy-mode-vi v if -F '#{selection_active}' 'send-keys -X clear-selection' 'send-keys -X begin-selection'
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind -T copy-mode-vi Escape send-keys -X cancel
bind -T copy-mode-vi C-c send-keys -X cancel
bind -T copy-mode-vi q send-keys -X cancel
bind -T copy-mode-vi WheelUpPane select-pane \; send-keys -X -N 2 scroll-up
bind -T copy-mode-vi WheelDownPane select-pane \; send-keys -X -N 2 scroll-down
# Session managment
bind 1 run-shell ~/.tmux/01.sh
bind 2 run-shell ~/.tmux/02.sh
bind 3 run-shell ~/.tmux/03.sh
bind 4 run-shell ~/.tmux/04.sh
bind 5 run-shell ~/.tmux/05.sh
bind 6 run-shell ~/.tmux/06.sh
bind 7 run-shell ~/.tmux/07.sh
bind 8 run-shell ~/.tmux/08.sh
bind 9 run-shell ~/.tmux/09.sh
bind 0 run-shell ~/.tmux/10.sh
# Switch to last session
bind Tab switch-client -l