Tmux Cheatsheet

I use linux terminal all day, and if you are like me, you should use tmux, which enables a number of terminals to be created, accessed, and controlled from a single screen, just to be more productive!
So, there're some essential commands for tmux down below.

start a new session

1tmux                              # session name will be 0,1,2, ... by default
2tmux new -s <session name>        # you can set a custom session name

rename an existing session

1tmux rename-session -t <old name> <new name>

detach current session

C-b d
C-b D

list running sessions

1tmux ls

attach an existing session

1tmux attach -t <session name>

or

1tmux a -t <session name>

split current pane horizontally

C-b %

split current pane vertically

C-b "

switch between panes

C-b <arrow key> # in direction
C-b o # by sequence

make the current pane full screen(same for exit)

C-b z

resize the current pane in an arrow direction

C-b C-<arrow key>

closing the current pane

C-d or exit

create a new window

C-b c

rename the current window

C-b ,

switch between windows

C-b p # previous
C-b n # next
C-b <num key> # by number

to use vim color scheme inside tmux

Create a tmux config file

1touch ~/.tmux.conf

Put these lines in the file:

1set -g default-terminal "xterm-256color"
2set -ga terminal-overrides ",*256col*:Tc"

wait, what? I can't scroll up/down inside tmux. it sucks, huh?

Nah, you can do it. You can get into scrolling mode by C-b [, and quit by q. Very cool :XD

even better, we can persist tmux sessions between reboots. soooo cool, isn't it?

Tmux has its own plugin ecosystem. A plugin called tmux-resurrect enables us to persist sessions across reboots.
So, there are two ways of installing tmux-resurrect plugin, and the manual way is my preferred one because I do not use many plugins for tmux.

1mkdir -p ~/.tmux
2cd ~/.tmux
3git clone https://github.com/tmux-plugins/tmux-resurrect

Then add this line to the bottom of ~/.tmux.conf:

1run-shell ~/.tmux/tmux-resurrect/resurrect.tmux

Reload tmux environment:

1tmux source-file ~/.tmux.conf

Wowooo, you are now able to persist any number of sessions across reboots

  • C-b C-s - save
  • C-b C-r - restore

That's it. Happy tmuxing! :XD

comments powered by Disqus