在另一个 tmux 会话中打开 tmux 会话时如何发送命令?
典型的情况可能是:
$ tmux
[0] $ ssh example.com
$ tmux attach
[0] $
我打开一个 tmux 会话,然后 ssh 到服务器并附加到现有的 tmux 会话。此时,我在另一个 tmux 会话中有一个 tmux 会话。如何向内部 tmux 会话发送命令?
注意:两个 tmux 会话具有相同的键绑定。
A typical situation may be:
$ tmux
[0] $ ssh example.com
$ tmux attach
[0] $
I open a tmux session, then ssh in to a server and attach to an existing tmux session. At this point I have one tmux session inside another. How do I send commands to the inner tmux session?
Note: Both tmux sessions have the same key bindings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
send-prefix
命令可用于将您的前缀击键发送到活动窗格(在其中运行的进程)。默认情况下,前缀为 Cb 并且 Cb 绑定到send-prefix
(因此点击两次会发送一个 Cb< /strong> 到活动窗格)。这正是我们访问内部 tmux 实例的绑定所需要的。第一个 Cb 由“外部”tmux 实例捕获作为其前缀键。第二个由“外部”tmux 实例捕获并触发其 Cb 绑定 (
send-prefix
)。这会将 Cb 发送到外部实例的活动窗格。在此窗格中运行的进程(最终通过 ssh 实例)是“内部”tmux 实例。它捕获 Cb 作为其前缀键。现在,您的下一次击键将通过外部 tmux 实例传递,并由内部实例捕获以触发绑定。要在 tmux 的二级实例中触发 c 绑定 (
new-window
),您可以输入 Cb Cb c< /强>。对于 tmux 的第三级实例,您可以输入 Cb Cb Cb Cb c。如果您通常处理多层tmux,那么每个级别的加倍可能会很烦人。如果您可以腾出一些其他键,您可以进行无前缀绑定以使输入(可能)更容易:
在二级tmux中创建新窗口:C-\ c< /strong>
在第三级tmux中创建新窗口:C-^ c(或C-\ C-\ c)
如果数量有限您想要(轻松)发送到较低级别的 tmux 实例的 tmux 命令,您可以使用
send-keys
创建一些特定的绑定(可能只是在你的顶层tmux实例):在二级tmux中创建新窗口:Cb Cc
在第三级tmux中创建新窗口:Cb C
The
send-prefix
command can be used to send your prefix keystroke to (the process running in) the active pane. By default, the prefix is C-b and C-b is bound tosend-prefix
(so that hitting it twice sends a single C-b to the active pane). This is just what we need to access the bindings of the inner tmux instance.The first C-b is captured by the “outer” tmux instance as its prefix key. The second one is captured by the “outer” tmux instance and triggers its C-b binding (
send-prefix
). This sends a C-b to the outer instance’s active pane. The process running in this pane is (ultimately, through an ssh instance) the “inner” tmux instance. It captures the C-b as its prefix key. Now your next keystroke will be passed through the outer tmux instance and captured by the inner one to trigger a binding.To trigger the c binding (
new-window
) in a second-level instance of tmux, you would type C-b C-b c. For a third-level instance of tmux you would type C-b C-b C-b C-b c.This doubling for each level can be annoying if you are commonly dealing with multiple layers of tmux. If you can spare some other key, you could make a non-prefixed binding to make things (possibly) easier to type:
Create new window in second-level tmux: C-\ c
Create new window in third-level tmux: C-^ c (or C-\ C-\ c)
If you have a limited number of tmux commands that you want to (easily) send to the lower-level tmux instances, you might instead use
send-keys
to create some specific bindings (possibly just in your top-level tmux instance):Create new window in second-level tmux: C-b C-c
Create new window in third-level tmux: C-b C
要进入内部,请按住 Control 键并按 B 两次。
To access the inner, hold control and hit B twice.
编辑:
我不建议使用
Cq
作为绑定键,因为它是默认的控制键命令为此处发生这种情况,@Paschalis 提供了解决方案:
下面就是答案:
为了简单起见,在您的
~/.tmux.conf
中添加以下行然后您可以直接使用
Cq
作为远程 tmux 的绑定密钥。EDIT:
I do NOT recommend use
C-q
as a bind-key, as it is a default control-key command forA situation happens here, and @Paschalis provides a solution:
Below it is the answer:
To make it simple, add the below line in your
~/.tmux.conf
Then you can directly use
C-q
as bind-key for your remote tmux.