Pages

Sunday, October 10, 2021

Power of tmux and cheatsheet 


Welcome to the post dedicated to the handy tool named Terminal MUltiplerXer, shortly tmuxtmux it the terminal tool and its big advantages is that it allows to keep eye on multiple opened programs (“command-lines”) within one terminal. This comes handy  during an interaction with multiple remote servers or cloud environments.

To install tmux on MacOs using brew use the following command:

$brew install tmux 

To confirm that all is properly installed just verify in command-line by typing:

$tmux -V

output:
tmux 3.2a 

Used terms:

Prefix, <prefix>: The key combination that must be entered before entering the shortcut key. 
The default prefix for MacOs or <Ctrl+b> for  linux.  
Session: this is entity managed by tmux. The session can be attached/detached. 
When session is detached the program continues to run (very handy)
Window: The window exist inside the session. tmux allows to have multiple 
windows inside the one session.
Pane: The pane is the unit that exist inside the window instance. It is possible to 
have multiple panes inside the window

Start tmux with the session name

#display shortcut keys
$tmux list-keys

# start only tmux
$ tmux 

# start tmux with named session
$tmux new -s <session_name>

# exit session 
$ exit

# attach session by name
$tmux attach -t <session_name>

# detach session
<prefix> + d 
$tmux kill-session -t <session_namne>

# list all sessions
<prefix> + : + ls
$tmux ls

# rename session
<prefix> + $

# reseting tmux
$tmux kill-server
The following sections are divided into target domains:

Sessions

# list available session:
$tmux ls

#start new session with name: 
$tmux new -s <session-name>
<prefix> :new - start a new session

#attach to named session: 
$tmux a -t <session-name>

#kill session:
$tmux kill-ses -t <sessio_name>
$tmux kill-session -t <session-name>
#kill/delete all session except current
$tmux kill-session -a  
#kill/delete all session except <session -name>
$tmux kill-session -a -t <session-name> 
<prefix> $  #rename session
<prefix> d  #detach session
<prefix> s  #show all session

#attach to the last session
$tmux a -t <session_name>
 
Resizing panes
# command are written after pressing <prefilx>  followed by : (COLON CHARACTER)
<prefilx> + :resize-pane -U <empty or number of cels resize  up>
<prefilx> + :resize-pane -D <empty or number of cels resize down>
<prefilx> + :resize-pane -L <empty or number of cels resize left>
<prefilx> +:resize-pane -R <empty or number of cels resize right>
<prefilx> + :resize-pane -t 2 -D 10 <resize the pane 2 by number of cells down, D resp. U,L,P,R> 
Copy mode
<prefix> + :setw -g mode-keys vi    # use vi keys in buffer
<prefix> + [	        # enter copy mode
<prefix> + PgUp		    # enter copy mode and scroll one page up
<prefix> + q 		    # quit mode
<prefix> + g		    # go to top line
<prefix> + G		    # go to bottom line
<prefix> + h or l	    # move cursor left, right
<prefix> + j or k	    # move cursor up, down
<prefix> + w or b       # move cursor forward/backward one word at a time
<A-UP/DOWN/LEFT/RIGHT>	# scroll up/down
<prefix> + /			# search forward
<prefix> + ?			# search backward
<prefix> + n 			# next keyword occurrence
<prefix> + N			# previous keyword occurrence
<prefix> + <SPACEBAR>	# start selection
<prefix> + <ESC>		# clear selection
<prefix> + <ENTER>		# copy selection
<prefix> +	]		    # paste contents of buffer_0
<prefix> + :show-buffer	    # display buffer_0 contents
<prefix> + :capture-pane	# copy entire visible contents of pane to a buffer
<prefix> + :list-buffers	# show all buffers
<prefix> + :choose-buffer   # show all buffers and paste selected
<prefix> + :save-buffer buf.txt	 # save buffer contents to buf.txt
<prefix> + :delete-buffer -b 1	 # delete buffer_1 

Tabs(window)

<preix> + c  	# create tab
<preix> + w 	# list tab
<preix> + n 	# next tab
<preix> + p 	# previous tab
<preix> + f     # find tab
<preix> + , 	# name tab
<preix> + & 	# kill  tab
<preix> + .	    # move tab for a new, not occupied, number 
<preix> + t	    # display time clock in the active pane
<preix> + 0…9   # swich/select window by number
<preix> + : + swap-window -s 2 -t 1  # reorder window, swap window number 2 and 1
<preix> + : +swap-window -t -1 # move current window to the left by -1 
Panes
<prefix> + :setw synchronize-panes
<prefix> + <space>      # toggle between layouts
<prefix> + ;	        # toggle last active pane
<prefix> + %		    # vertical split
<prefix> + “            # horizontal split
<prefix> + o		    # swap panes
<prefix> + q		    # show pane numbers
<prefix> + q 0..9	    # select/switch pane by number
<prefix> + x		    # kill pane
<prefix> + z		    # toggle pane zoom
<prefix> + !		    # convert pane into a window
<prefix> + +		    # break pane into window  (investigate how)
<prefix> + -	        # restore pane from window (investigate how)
<prefix> + {	        # move current pane left
<prefix> + }	        # move current pane right
<prefix> + <ARROWS>     # switch to pane in the Arrow direction
<prefix> + <C-ARROWS>   # resize current pane with in direction 
Synchronize panes
# pretty useful when you plan to do similar action in all panes
<prefix> + :setw synchronize-panes on
<prefix> + :setw synchronize-panes off 
Misc
<prefix> +	:	            # enter command mode
<prefix> + :set -g OPTION 	# set OPTION for all sessions
<prefix> + :setw -g OPTION 	# set Option for all windows
<prefix> + :set mouse on	# enable mouse mode 
Help
$man tmux    #get man page
$ tmux list-keys
<prefix> + :list-keys
<prexi> ? 			    #list key bindings (shortcuts) 
Happy Tmuxing ! :) 
Link: wengneritsolutions - lab - tmux

No comments: