# tmux reference
https://wiki.archlinux.org/title/Tmux
https://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/
https://www.seanh.cc/2020/12/28/binding-keys-in-tmux/
https://www.seanh.cc/2020/12/28/setting-options-in-tmux/

bind is the alias of bind-key
set is the alias of set-option
setw is the alias of set-window-option

To list all current key bindings, including any custom bindings you've added and
bindings added by plugins:
* ctrl + a ?
* tmux list-keys or tmux lsk in a shell inside tmux
* list-keys or lsk at tmux's command prompt (ctrl + a :)

# display current tmux configuration
tmux show-options -g | grep status

# assign ctrl + a as prefix key
ctrl + a and ctrl + --->        # resize pane
ctrl + a and z                  # full screen/no full screen

tmux                            # start tmux
tmux new -s < name >            # start tmux with
tmux ls/list-sessions           # list-sessions currently running on tmux
tmux attach -t n                # attach session number n (-t = target session)
tmux list-windows -a            # list-sessions when running inside another tmux
tmux move-window -s n1 -t n2    # -s (source window), (-t target window)
# Example: (sessionNo:windowNo) # n1 (number of the window you want to move)
tmux move-window -s 0:3 -t 1:4  # n2 (number of the window you are moving to)
ctrl + a and d                  # detach the current client
ctrl + a and D                  # choose a client to detach
tmux kill-session               # kill-session (default: when only one session)
tmux kill-session -t n          # kill-session number n (-t = target session)
tmux kill-server                # kill all session

# moving a pane
tmux list-panes -a              # list-panes
tmux list-panes -t 0:1          # list-panes in sessionNo = 0 and windowNo = 1

# display current running commands at each pane:
tmux list-panes -F "#{pane_current_command}" -t 0:1

ctrl-s                          # search
ctrl-a and q                    # show number

Alt + Enter                     # create new window
Alt + a                         # toggle windows
Alt + n                         # next window
Alt + p                         # previous window

# help
ctrl-a and ?                    # show the list of commands

# reload
ctrl-a and r                    # reload tmux.conf file

# sessions
ctrl-a and s                    # list sessions
ctrl-a and $                    # rename sessions
ctrl-a and d                    # detach session

# windows
ctrl-d can be used to close the window or panes without ctrl-a
ctrl-a and w                    # list windows and select one
ctrl-a and ,                    # rename window
ctrl-a and c                    # create new window
ctrl-a and n                    # next window
ctrl-a and p                    # previous window
ctrl-a and f                    # find window
ctrl-a and &                    # kill window
ctrl-a and 0-9                  # select window 0-9

# panes (split windows)
ctrl-a and -                    # vertical split
ctrl-a and =                    # horizontal split
ctrl-a and x                    # kill pane
ctrl-a and o                    # next pane
ctrl-a and h,j,k,l              # vi-like keybindings
ctrl-a and z                    # toggle full-screen mode for current pane
ctrl-a and arrow keys           # resize the pane
ctrl-a and q                    # show pane-numbers

# commands
ctrl-a and :                    # command mode
then, type the commands as below,
list-keys                       # shows all the commands
list-panes                      # shows the names of all panes
resize-pane-D 20                # resize down
resize-pane-U 20                # resize up
resize-pane-L 20                # resize left
swap-pane -s 3 -t 1             # swap pane '1' with pane '3'

# copy mode
Esc                             # copy mode
then, use the following commands without using 'ctrl-a'
q                               # quit mode
h,j,k,l                         # left, down, up, right
J or k                          # scroll down or up
F or B                          # go to next or previous page
$                               # go to end of line
O                               # go to beginning of line
w or b                          # go to next or previous word
/ or ?                          # search forward or backward
n                               # search next (use after above commands)
space                           # start selection
Esc                             # clear selection
y                               # copy selection
ctrl-a and p                    # paste selection
