实用工具集合之tmux

2016-06-29

tmux

银弹特性:

  1. 同一窗口分割多面板

    与vim配置好后用起来就真的不再需要鼠标了。也不用在编辑器和命令行各个窗口中切来切去了。全屏一个窗口解决。

  2. session可恢复

    超时、断网等问题造成的远程连接中断,重新连接后可恢复会话窗口

Tmux - Linux从业者必备利器

效果截图:

tmux效果截图

session会话操作

1
2
3
4
5
6
7
8
9
10
11
(prefix指前缀键组合,默认为ctrl+b,我设置为ctrl+x了,顺手)
prefix :new -s <name>, 创建session,名为name
prefix s 列出所有session (可选择进入)
prefix $ session重命名
prefix (   preview session
prefix )   next session

tmux ls 列出所有session
tmux new -s "session_name"       // 创建一个seesion
tmux attach -t session           // 进入指定的会话(可终端共享)
tmux kill-session -t "session"   // 删除指定会话

使用鼠标操作

用的Mac自带的Terminal,无法设置鼠标操作和滚轮翻屏

解决方法:使用tmux插件tmux-scroll-copy-mode

使用tmux-plugins/tpm来管理tmux插件

按照如下步骤安装插件:

1
2
3
4
5
1. .tmux.conf配置文件中添加 `set -g @plugin 'nhdaly/tmux-scroll-copy-mode'`

2. 在tmux终端使用命令`prefix + I`(自定义前缀+I),会自动按照插件

3. .tmux.conf中添加开启鼠标模式 `set-option -g mouse on`

具体参考:NHDaly/tmux-scroll-copy-mode

我的配置:

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
#设置前缀为Ctrl + x                                                                           
set -g prefix C-x
#将r 设置为加载配置文件,并显示"reloaded!"信息
bind r source-file ~/.tmux.conf \; display "Reloaded!"
#up 窗口切换
bind-key k select-pane -U
#down
bind-key j select-pane -D
#left
# bind-key h select-pane -L
#right
#bind-key l select-pane -R
#分割面板, 原为"竖直 %水平
# |竖直 -水平
bind | split-window -v
bind - split-window -h
#调整pane大小 tmux大小写敏感,-r可重复
bind -r H resize-pane -L
bind -r J resize-pane -D
bind -r K resize-pane -U
bind -r L resize-pane -R
#允许鼠标操作,滚屏
set-option -g mouse on

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'nhdaly/tmux-scroll-copy-mode'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

  • 本文作者: xiaodongQ
  • 本文链接: /2016/06/29/tools-tmux/
  • 版权声明: 本文可以自由拷贝,转载,请注明出处,谢谢! 🤝

Comments