tmux教程
功能
分屏。
允许断开Terminal连接后,继续运行进程。
结构
一个tmux可以包含多个session,一个session可以包含多个window,一个window可以包含多个pane。
常用操作
tmux
:新建一个session,其中包含一个window,window中包含一个pane,pane里打开了一个shell对话框。
tmux kill-server
:关闭所有session
按下Ctrl + B
后松开,然后按%
(shift + 5
):将当前pane左右平分成两个pane
按下Ctrl + B
后松开,然后按"
:将当前pane上下平分成两个pane。
Ctrl + D
:关闭当前pane;
如果当前window的所有pane均已关闭,则自动关闭window;如果当前session的所有window均已关闭,则自动关闭session。
鼠标点击可以选pane。(我鼠标动不了)
按下Ctrl + B
后松开,然后按方向键
:选择相邻的pane。
鼠标拖动pane之间的分割线,可以调整分割线的位置。
按住Ctrl + B
的同时按方向键
,可以调整pane之间分割线的位置。
按下Ctrl + B
后松开,然后按z
:将当前pane全屏/取消全屏。
按下Ctrl + B
后松开,然后按d
:挂起当前session。
tmux a
:打开之前挂起的session。
按下Ctrl + B
后松开,然后按s
:选择其它session。
方向键 —— 上:选择上一项 session/window/pane
方向键 —— 下:选择下一项 session/window/pane
方向键 —— 右:展开当前项 session/window
方向键 —— 左:闭合当前项 session/window
按下Ctrl + B
后松开,然后按c
:在当前session中创建一个新的window。
按下Ctrl + B
后松开,然后按w
:选择其他window,操作方法与(12)完全相同。
按下Ctrl + B
后松开,然后按PageUp
:翻阅当前pane内的内容。
鼠标滚轮:翻阅当前pane内的内容。
在tmux中选中文本时,需要按住shift键。(仅支持Windows和Linux,不支持Mac)
tmux中复制/粘贴文本的通用方式:
- 按下
Ctrl + B
后松开,然后按[
- 用鼠标选中文本,被选中的文本会被自动复制到tmux的剪贴板
- 按下
Ctrl + B
后松开,然后按]
,会将剪贴板中的内容粘贴到光标处
安装tmux
无网络使用appImages版本: apps – AppImages
Releases · nelsonenzo/tmux-appimage (github.com)
1
2
| chmod +x ./tmux.appimage # 下载后,添加权限
cp tmux.appimage /usr/local/bin/tmux # 放到PATH环境变量记录的文件夹下,以便在任意地方直接调用
|
配置文件 ~/.tmux.conf
令其生效两种方式:
1:tmux source-file ~/.tmux.conf
2:在tmux窗口中,先按下Ctrl+b
指令前缀,然后按下系统指令:
,进入到命令模式后输入source-file ~/.tmux.conf
,回车后生效。
ctrl + B 改成 ctrl + A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| set-option -g status-keys vi
setw -g mode-keys vi
setw -g monitor-activity on
# setw -g c0-change-trigger 10
# setw -g c0-change-interval 100
# setw -g c0-change-interval 50
# setw -g c0-change-trigger 75
set-window-option -g automatic-rename on
set-option -g set-titles on
set -g history-limit 100000
#set-window-option -g utf8 on
# set command prefix
set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
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
bind < resize-pane -L 7
bind > resize-pane -R 7
bind - resize-pane -D 7
bind + resize-pane -U 7
bind-key -n M-l next-window
bind-key -n M-h previous-window
set -g status-interval 1
# status bar
set -g status-bg black
set -g status-fg blue
#set -g status-utf8 on
set -g status-justify centre
set -g status-bg default
set -g status-left " #[fg=green]#S@#H #[default]"
set -g status-left-length 20
# mouse support
# for tmux 2.1
# set -g mouse-utf8 on
set -g mouse on
#
# for previous version
#set -g mode-mouse on
#set -g mouse-resize-pane on
#set -g mouse-select-pane on
#set -g mouse-select-window on
#set -g status-right-length 25
set -g status-right "#[fg=green]%H:%M:%S #[fg=magenta]%a %m-%d #[default]"
# fix for tmux 1.9
bind '"' split-window -vc "#{pane_current_path}"
bind '%' split-window -hc "#{pane_current_path}"
bind 'c' new-window -c "#{pane_current_path}"
# run-shell "powerline-daemon -q"
# vim: ft=conf
|