This post is first created by CodingMrWang, 作者 @Zexian Wang ,please keep the original link if you want to repost it.
Tmux is really useful during work, espically when you run a program on a virtual machine and it may last for a long time. Using tmux could allow you close your mac and check the process when you want later.
install tmux in mac
brew install tmux
Start Tmux
tmux
You can also cutomize the theme of your tmux.
vim ~/.tmux.conf
Here I list some changes of the color and function bar you could add.
set -g message-style "bg=#00346e, fg=#ffffd7" # tomorrow night blue, base3
set -g status-style "bg=#00346e, fg=#ffffd7" # tomorrow night blue, base3
set -g status-left "#[bg=#0087ff] ❐ #S " # blue
set -g status-left-length 400
set -g status-right "#{?client_prefix, ~ , } #[bg=#0087ff] #h #[bg=red] %Y-%m-%d %H:%M "
set -g status-right-length 600
set -wg window-status-format " #I #W "
set -wg window-status-current-format " #I #W "
set -wg window-status-separator ""
set -wg window-status-current-style "bg=red" # red
set -wg window-status-last-style "fg=red"
Then you can use ⌃b to go to control mode and enter source-file ~/.tmux.conf to use the tmux new config. Here is my tmux.
Next, I introduce hot kyes of Tmux. When you are in the shell main process
tmux new -s hello create a new session named hello
tmux ls list all tmux sessions
tmux a go back to last session
tmux kill-session -t hello kill hello session
tmux kill-server kill all sessions
In tmux, the hot keys contains ⌃b at the beginning. So you need to enter control b first, then enter the following hot keys.
Pane Operation
% split the pane vertically
" split the pane horizontally
x Close current pane
{ move cuurent pane forward
} move current pane backward
; choose the pane last used
o choose next pane
<-/-> go to left/right pane
space change pane location
z maximize current pane
q show all pane‘s number
Window Operation
c create a new window
p go to previous window
n go to next window
& close current window
, rename the window
id go to id window
f search window
Copy mode
In tmux, move the screen is not convenient, you can set to use mouse to move the screen by running
# start mouse mode
tmux set -g mode-mouse on
# allow mouse to choose pane
set -g mouse-select-pane on
or
[ go to the copy mode
q quit the copy mode
To be continue