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 shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname

attach:

tmux a  #  (or at, or attach)

attach to named:

tmux a -t myname

list sessions:

tmux ls

kill session:

tmux kill-session -t myname

In tmux, hit the prefix ctrl+b (my modified prefix is ctrl+a) and then:

Sessions

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

Windows (tabs)

c  new window
w  list windows
f  find window
,  name window
&  kill window

Panes (splits)

%  horizontal split
"  vertical split

o  swap panes
q  show pane numbers
x  kill pane
+  break pane into window (e.g. to select text by mouse to copy)
-  restore pane from window
⍽  space - toggle between layouts
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)

Resizing Panes

Resizing Panes

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 (By default it 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 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)

Copy mode:

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.

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:

TODO:

@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