Tmux
Jump to navigation
Jump to search
This page is for collecting various snippets and pieces for use with tmux.
Quick cheat sheet of helpful tmux commands
Source: [1]
tmux new
- Create and attach to a new session.tmux new -s NAME_HERE
- Create and attach to a new session named NAME_HERE.CTRL-b, d
- Detach (i.e. exit) from the currently-opened tmux session (alternatively, `tmux detach`). Note, this means press and hold `CTRL`, press `b`, release both, press `d`.tmux ls
- Show list of tmux sessions.tmux a
- Attach to the previously-opened tmux session.tmux a -t NAME_HERE
- Attach to the tmux session named NAME_HERE.CTRL-d
- Delete (i.e. kill) currently-opened tmux session (alternatively `tmux kill-session`).CTRL-b, [
- Enter copy mode, and enable scrolling in currently-opened tmux session. Press `q` to exit.CTRL-b, "
- Split window horizontally (i.e. split and add a pane below).CTRL-b, %
- Split window vertically (i.e. split and add a pane to the right).CTRL-b, UpArrow
- Move to the pane above (I prefer to rebind this to `CTRL-b, k` to be similar to Vim).CTRL-b, DownArrow
- Move to the pane below (I prefer to rebind this to `CTRL-b, j` to be similar to Vim).CTRL-b, LeftArrow
- Move to the pane to the left (I prefer to rebind this to `CTRL-b, h` to be similar to Vim).CTRL-b, RightArrow
- Move to the pane to the right (I prefer to rebind this to `CTRL-b, l` to be similar to Vim).CTRL-b, z
- Toggle maximization of current pane.CTRL-b, ESC, 2
- Resize all panes to equal size.CTRL-b, q
- Show pane numbers.CTRL-b, x
- Kill current pane.CTRL-b, c
- Create a new window.CTRL-b, n
- Switch to next window.CTRL-b, p
- Switch to previous window.CTRL-b, 3
- Switch to window 3.CTRL-b, CTRL-b, COMMAND
- Send the command to a nested tmux session (repeat prefix for each level of nesting).
Dump live tmux buffer to a file
Source: [1]
CTRL-b,
- to enter the command modecapture-pane -S -32768 ; save-buffer FILENAME_HERE
- to save at least the last 32,768 lines from the buffer
Configuration file additions
Alt arrow keys
Use Alt-arrow keys without prefix key to switch panes[2]
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
Shift + arrow keys to switch windows[2]
bind -n S-Left previous-window bind -n S-Right next-window
Zoom window
Zoom Window - Useful for when you need to copy text out of a pane to your local clipboard without selecting text in other panes.[2]
unbind ! bind ! \ new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\ swap-pane -s tmux-zoom.0 \;\ select-window -t tmux-zoom unbind ` bind ` \ last-window \;\ swap-pane -s tmux-zoom.0 \;\ kill-window -t tmux-zoom
Sync panes
Sync panes (Send input to all panes in the window). When enabled, pane borders become red as an indication.[2]
bind-key y set-window-option synchronize-panes on \;\ set-window-option pane-active-border-style fg=red \;\ set-window-option pane-border-style fg=yellow \;\ display-message "Sync panes ON" bind-key Y set-window-option synchronize-panes off \;\ set-window-option pane-active-border-style fg=green \;\ set-window-option pane-border-style default \;\ display-message "Sync panes OFF"
Bash Multi Command (works with panes)
Source: [2]
Works with tmux sync panes and spawns a new per argument and then sync them.
Useful for running ssh to multiple machines at same time, or issuing multiple commands at once.
Try it with:
multi ping 127.0.0.{1..10}
or
multi ssh server{1..5}
Configuration snippet:
function multi { cmd=$1 shift while $cmd = "ssh" ; do pre_check="$(echo $@ | tr ' ' '\n' | sed -e 's/^.*@//g' | \ xargs nmap -p 22 -PN -oG - | grep Port | grep -v open)" test "${pre_check}x" != "x" && (clear; echo "$pre_check") || break done tmux send-keys -t 0 "$cmd ${@[1]}" for ((pane = 1; pane < ${#@[@]}; pane++)); do tmux splitw -h tmux send-keys -t $pane "$cmd ${@[pane+1]}" tmux select-layout tiled > /dev/null done tmux set-window-option synchronize-panes on > /dev/null tmux set-window-option pane-active-border-style fg=red > /dev/null tmux set-window-option pane-border-style fg=yellow > /dev/null tmux send-keys Enter }
Reload tmux configuration
Source: [1]
tmux source-file ~/.tmux.conf