Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save zombie110year/1f02c500eae2006f2d0fd958a242aece to your computer and use it in GitHub Desktop.

Select an option

Save zombie110year/1f02c500eae2006f2d0fd958a242aece to your computer and use it in GitHub Desktop.
tmux 快捷键 & 速查表

tmux 快捷键与速查表

新建会话(按照从 0 开始的编号命名):

tmux new

以指定的命名新建会话:

tmux new -s myname

附加到上一个会话:

tmux a  #  (or at, or attach)

附加到名称指定的会话:

tmux a -t myname

列出所有会话:

tmux ls

销毁会话:

tmux kill-session -t myname

销毁所有会话:

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

在 tmux 中, <ctrl> b 组合键被称为 <prefix> 键, 这个键是许多快捷键的前缀键, 可以在配置文件中修改为喜欢的按键. 下面的键位都是在按下 <prefix> 之后的操作:

Sessions

:new<CR>  new session
s  列出所有会话
$  命名会话

窗口(标签页)

c  新建
w  列出
n  向后切换
p  向前切换
f  查找
,  命名
&  销毁

面板(Splits)

%  垂直分割
"  水平分割

o  切换焦点
q  显示编号, 之后可点击相应编号切换焦点到目标面板
x  销毁
+  将面板转换为窗口, 以便复制内容
-  将窗口转换为面板
<space>  转化布局(全水平, 全垂直, 原布局)
{  将当前面板前移
}  将当前面板后移
z  触发面板缩放(最大化, 复位)

同步面板

你可以输入 <prefix> : 进入命令模式, 在状态栏弹出的命令行中执行命令以完成以下操作:

:setw synchronize-panes

您可以选择添加或关闭以指定所需的状态;, 否则只需切换选项. 此选项特定于一个窗口, 因此不会更改其他会话或窗口的运行方式. 完成后, 通过重复命令再次将其关闭. [tip source](http://blog.sanctum.geek.nz/sync-tmux-panes/)

重设面板尺寸

你如果对默认布局不满意, 可以使用快捷键进行尺寸的设置, 也可以使用这些命令:

resize-pane -D (将当前面板边界下移)
resize-pane -U (将当前面板边界上移)
resize-pane -L (将当前面板边界左移)
resize-pane -R (将当前面板边界右移)
resize-pane -D 20 (将当前面板边界下移 20 个单位)
resize-pane -U 20 (将当前面板边界上移 20 个单位)
resize-pane -L 20 (将当前面板边界左移 20 个单位)
resize-pane -R 20 (将当前面板边界右移 20 个单位)
resize-pane -t 2 20 (将 2 号面板边界下移 20 个单位)
resize-pane -t -L 20 (将 2 号面板边界左移 20 个单位)

复制模式

按下 <prefix> [ 组合键进入复制模式. 可以使用移动键来将光标在缓冲区中移动. 默认情况下使用方向键. 也可以在配置文件中指定为 vim 或 emaces 的移动模式. 在 .tmux.conf 中编辑:

setw -g mode-keys vi

当这个选项启用后, 就可以把 h, j, k, l 当作方向键使用了.

要退出复制模式, 按回车键 <enter>. 一次移动一个字符是低效的, 在启用 Vim 的移动模式后, 就可以使用更多的快捷键来进行移动.

例如, 使用 "w", "b" 一次移动一个单词, 使用 f 跳转到下一个搜索的字符处, 以及使用 F 向前跳转.

Function vi emacs
Back to indentation ^ <alt> m
Clear selection <esc> <ctrl> g
Copy selection <enter> <alt> w
Cursor down j <down>
Cursor left h <left>
Cursor right l <right>
Cursor to bottom line L
Cursor to middle line M <alt> r
Cursor to top line H <alt> R
Cursor up k <up>
Delete entire line d <ctrl> u
Delete to end of line D <ctrl> k
End of line $ <ctrl> e
Goto line : g
Half page down <ctrl> d <alt> <down>
Half page up <ctrl> u <alt> <up>
Next page <ctrl> f <PageDown>
Next word w <alt> f
Paste buffer p <ctrl> y
Previous page <ctrl> b <PageUp>
Previous word b <alt> b
Quit mode q <esc>
Scroll down <ctrl> <down>J <ctrl> <down>
Scroll up <ctrl> <up>K <ctrl> <up>
Search again n n
Search backward ? <ctrl> r
Search forward / <ctrl> s
Start of line 0 <ctrl> a
Start selection <space> <ctrl> <space>
Transpose chars <ctrl> t

Misc

d  退出
t  显示时钟
?  列出快捷键
:  命令提示符

Configurations Options:

# Mouse support - set to on if you want to use the mouse
* setw -g mode-mouse off
* set -g mouse-select-pane off
* set -g mouse-resize-pane off
* set -g mouse-select-window off

# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on

# Center the window list
set -g status-justify centre

# Maximize and restore a pane
unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp

Resources:

Notes:

Changelog:

Request an Update:

详见英文原版: MohamedAlaa - gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment