下载/基础知识
- ubuntu下载命令:sudo apt install tumx
- tmux最重要的三个概念:session会话、window窗口、pane面板,session可以包含多个window, 每个window又可以包含多个pane。如下图所示:
ctrl + b为前缀键 - 创建会话命令:
tmux new -s <session name>
- 创建新的window:
ctrl b + c
- 切换window:
ctrl b + w
- 左右分屏:
ctrl b
再按%
- 上下分屏:
ctrl b
再按"
- 光标在不同窗口中移动:
ctrl + b
+ 方向键 - 退出当前窗口:
exit
- 查看当前所有窗口:
tmux ls
- 退出某个序号的窗口
tmux kill-window -t <num>
- 退出当前会话:
ctrl b + d
- 改当前窗口名字:
ctrl b + ,
- 删除会话:
tmux kill-session -t <session name>
- 查看当前所有会话:
tmux list
- 连接到当前正在运行的会话:
tmux attach-session -t<list>
keys + options
因为ctrl + b
的前缀键非常不直观,所以我们要remap这个键。步骤如下:
1、首先创建一个配置文件touch ~/.tmux.conf
,在文件内输入
unbind %
bind | split-window -h "#{pane_current_path}"
unbind '"'
bind - split-window -v "#{pane_current_path}"
unbind r
bind r source-file ~/.tmux.conf
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5
bind -r m resize-pane -Z 5
set -g mouse on
set -g mode-keys vi
bind | split-window -h
解绑%
,绑定|
,并且新的窗口和原窗口处在同一个directory
bind r source-file ~/.tmux.conf
以后更改完配置文件不需要每次都source文件,只需要ctrl + b + r
bind -r j resize-pane -D 5
resize面板大小,ctrl + b + j/k/l/h
只需要按一次ctrl + b
,就能连按很多次j/k/l/h
,ctrl + b + m
最大化
set -g mouse on
打开鼠标
set -g mode-keys vi
移动模式设置为vi的移动模式,即j/k/l/h
等
2、推出配置文件,输入ctrl b:source-file ~/.tmux.conf
,此时,刚才的配置全部生效。
3、ctrl b:list-keys
可以看到所有的快捷键
-r
可以按多次
-T
不需要按前置键
copy mode
ctrl + b + [
进入copy mode
ctrl + c
退出
插件
set -g @plugin 'tmux-plugins/tpm'
#list of tmux plugin
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'jimeh/tmux-themepack'
set -g @plugin 'tmux-plugins/tmux-resurrect'#persist tmux sessions after computer restart
set -g @plugin 'tmux-plugins/tmux-continuum'#automatically saves sessions for you every 15 minutes
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
#initialize tmux plugin manager
run '~/.tmux/plugins/tpm/tpm'
先执行git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
,在按ctrl b + I
最后ctrl b + r
保存修改