Skip to content

Instantly share code, notes, and snippets.

@ryerh
Forked from MohamedAlaa/tmux-cheatsheet.markdown
Last active October 30, 2025 09:01
Show Gist options
  • Save ryerh/14b7c24dfd623ef8edc7 to your computer and use it in GitHub Desktop.
Save ryerh/14b7c24dfd623ef8edc7 to your computer and use it in GitHub Desktop.
Tmux 快捷键 & 速查表 & 简明教程

tmux 快捷键 & 速查表

启动新会话:

tmux

启动名为 myname 的新会话:

tmux new -s myname

恢复会话:

tmux a  #(等价于 at 或 attach)

恢复名为 myname 的会话:

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(我的配置修改为 ctrl+a),然后:

会话:

:new<CR>  new session
s  list sessions
$  name session

窗口 (标签页)

c  create window
w  list windows
n  next window
p  previous window
f  find window
,  name window
&  kill window

窗格(分割窗口)

%  垂直分割
"  水平分割

o  交换窗格
q  显示窗格数量
x  关闭窗格
+  break pane into window (e.g. to select text by mouse to copy)
-  restore pane from window
⍽  space - 切换布局
<prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane)
<prefix> { (Move the current pane left)
<prefix> } (Move the current pane right)
<prefix> z toggle pane zoom

同步窗格

You can do this by switching to the appropriate window, typing your Tmux prefix (commonly Ctrl-B or Ctrl-A) and then a colon to bring up a Tmux command line, and typing:

:setw synchronize-panes

You can optionally add on or off to specify which state you want; otherwise the option is simply toggled. This option is specific to one window, so it won’t change the way your other sessions or windows operate. When you’re done, toggle it off again by repeating the command. tip source

调整窗格尺寸

如果你不喜欢默认布局,可以重调窗格的尺寸。尽管这很容易实现,但我一般没必要这么干。

You can also resize panes if you don’t like the layout defaults. I personally rarely need to do this, though it’s handy to know how. Here is the basic syntax to resize panes:

PREFIX : resize-pane -D (Resizes the current pane down)
PREFIX : resize-pane -U (Resizes the current pane upward)
PREFIX : resize-pane -L (Resizes the current pane left)
PREFIX : resize-pane -R (Resizes the current pane right)
PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells)
PREFIX : resize-pane -U 20 (Resizes the current pane upward by 20 cells)
PREFIX : resize-pane -L 20 (Resizes the current pane left by 20 cells)
PREFIX : resize-pane -R 20 (Resizes the current pane right by 20 cells)
PREFIX : resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
PREFIX : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)

文本复制模式:

按下前缀 [

Pressing PREFIX [ places us in Copy mode. We can then use our movement keys to move our cursor around the screen. By default, the arrow keys work. we set our configuration file to use Vim keys for moving between windows and resizing panes so we wouldn’t have to take our hands off the home row. tmux has a vi mode for working with the buffer as well. To enable it, add this line to .tmux.conf:

setw -g mode-keys vi

With this option set, we can use h, j, k, and l to move around our buffer.

To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isn’t very efficient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buffer.

For example, we can use "w" to jump to the next word and "b" to jump back one word. And we can use "f", followed by any character, to jump to that character on the same line, and "F" to jump backwards on the line.

   Function                vi             emacs
   Back to indentation     ^              M-m
   Clear selection         Escape         C-g
   Copy selection          Enter          M-w
   Cursor down             j              Down
   Cursor left             h              Left
   Cursor right            l              Right
   Cursor to bottom line   L
   Cursor to middle line   M              M-r
   Cursor to top line      H              M-R
   Cursor up               k              Up
   Delete entire line      d              C-u
   Delete to end of line   D              C-k
   End of line             $              C-e
   Goto line               :              g
   Half page down          C-d            M-Down
   Half page up            C-u            M-Up
   Next page               C-f            Page down
   Next word               w              M-f
   Paste buffer            p              C-y
   Previous page           C-b            Page up
   Previous word           b              M-b
   Quit mode               q              Escape
   Scroll down             C-Down or J    C-Down
   Scroll up               C-Up or K      C-Up
   Search again            n              n
   Search backward         ?              C-r
   Search forward          /              C-s
   Start of line           0              C-a
   Start selection         Space          C-Space
   Transpose chars                        C-t

Misc

d  detach
t  big clock
?  list shortcuts
:  prompt

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:

We Noticed that our Cheatsheet is growing and people are coloberating to add new tips and tricks, so please tweet to me what would you like to add and let's make it better!

@yottaliu
Copy link

C-z还是有冲突,我建议C-j或C-m

@huahuayu
Copy link

C-z还是有冲突,我建议C-j或C-m

`相当好用,就是数字1左边的键

@jahentao
Copy link

怎样方便地在多个窗格间切换呢?

@PoacherBro
Copy link

good, mark~~

@ryerh
Copy link
Author

ryerh commented Jun 24, 2019

@jahentao
如果使用了 tmux-plugins/tmux-pain-control 这个插件,可以看一下它的文档。
如果没用插件,<Prefix> 上下左右

@alphadl
Copy link

alphadl commented Jul 13, 2019

@zh794390558
Copy link

good

@hanzhangyu
Copy link

另外推荐一个配置:

# 分屏保留当前pane pwd
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

@Zhang21
Copy link

Zhang21 commented Nov 6, 2019

👍

@ryerh
Copy link
Author

ryerh commented Nov 15, 2019

@hanzhangyu 你提到的这个点,我一直在用 tmux-plugins/tmux-pain-control 插件,效果一样。

@susntones
Copy link

👍

@kuyeshiwo
Copy link

优秀

@haohuifeng0
Copy link

🚀🚀🚀🚀🚀🚀🚀

@Ethan-Yan27
Copy link

Ethan-Yan27 commented May 7, 2020

A small tip:
when configuring the .tmux.conf, try the command below to active the settings without restarting tmux.

<prefix> :source-file /absolute/path/to/your/.tmux.conf

@mayouzi
Copy link

mayouzi commented May 7, 2020

awesome boy

@Zhang21
Copy link

Zhang21 commented May 8, 2020

你好,请问一个问题。在tmux的基础上ssh远程主机,这时远程主机的tmux分屏是本地的环境。如何在远程主机中使用它的tmux进行分配。

这个好像是tmux ssh tmux inside

@doitthink
Copy link

非常感谢!

@XiaotaoGuo
Copy link

marked

@onionwyl
Copy link

onionwyl commented Nov 4, 2020

mark

@1dayluo
Copy link

1dayluo commented Nov 17, 2021

感谢分享

@kdbreboot
Copy link

cool

Copy link

ghost commented Jan 18, 2022

thanks.

@ferstar
Copy link

ferstar commented Apr 25, 2022

你好,请问一个问题。在tmux的基础上ssh远程主机,这时远程主机的tmux分屏是本地的环境。如何在远程主机中使用它的tmux进行分配。

这个好像是tmux ssh tmux inside

按两次<prefix>即可,无尽套娃

@Zhang21
Copy link

Zhang21 commented Apr 26, 2022

你好,请问一个问题。在tmux的基础上ssh远程主机,这时远程主机的tmux分屏是本地的环境。如何在远程主机中使用它的tmux进行分配。
这个好像是tmux ssh tmux inside

按两次<prefix>即可,无尽套娃

可以了,厉害啊。谢谢!

我的操作:

tmux, ctrl + b, ctrl +b, 之后分屏就行

@stevenlyf428
Copy link

你好,不是很懂-t是什么意思,
新建会话tmux new -s XXX
接入会话tmux a -t XXX

为什么对于会话的操作统一成一个参数,比如-s。

tmux命令好反人类,头大,QAQ

@stevenlyf428
Copy link

好像知道了,-t是tmux,QAQ

@andywu1998
Copy link

另外推荐一个配置:

# 分屏保留当前pane pwd
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

亲测有效,非常感谢 @hanzhangyu

@hanzhangyu
Copy link

hanzhangyu commented Sep 12, 2023 via email

@yunfeiguan
Copy link

非常不错,感谢。

@Robin0315
Copy link

很好,非常感谢。

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