通过ZSH脚本在正常模式下触发TMUX前缀?
我一直在设置终端,并且有 zsh-vi-mode 我在命令行中的模态编辑。我住在TMUX中,最近我想到在ZSH的正常模式下,用我的VIM领导者键(空间)代替TMUX前缀。
本质上,我想做的是仅在正常模式下以ctrl+b(tmux前缀)的空间(tmux前缀)
。我的.zshrc
:
function vim_to_tmux_leader() {
osascript -e 'tell application "System Events" to keystroke "b" using {control down}'
}
# The plugin will auto execute this zvm_after_lazy_keybindings function
function zvm_after_lazy_keybindings() {
zvm_define_widget vim_to_tmux_leader
# In normal mode, press Ctrl-B to access tmux
zvm_bindkey vicmd ' ' vim_to_tmux_leader
}
这显然是一个丑陋的黑客,因为我使用Apple脚本将CTRL B键击球发送到我的终端。尽管它有效,但有很大的延迟,因此我必须在按空间后等待〜0.5s,然后才能按下任何Tmux Hotkey才能正确注册。
我觉得必须有一种更好的方法来做到这一点。有没有办法(1)将密钥组合从本地ZSH发送回终端,或(2)以某种方式缓冲空间后的任何后续关键要等到osascript
命令完成执行?
I've been setting up my terminal and I have zsh-vi-mode which gives me modal editing at the command line. I live in tmux, and I recently had the idea of replacing the tmux prefix with my vim leader key (space) when in normal mode in zsh.
Essentially, what I'd like to be able to do is alias space to ctrl+b (the tmux prefix) only when in normal mode.
I've been able to somewhat accomplish this with the following in my .zshrc
:
function vim_to_tmux_leader() {
osascript -e 'tell application "System Events" to keystroke "b" using {control down}'
}
# The plugin will auto execute this zvm_after_lazy_keybindings function
function zvm_after_lazy_keybindings() {
zvm_define_widget vim_to_tmux_leader
# In normal mode, press Ctrl-B to access tmux
zvm_bindkey vicmd ' ' vim_to_tmux_leader
}
This is clearly an ugly hack as I use apple script to send the ctrl b keystrokes to my terminal. Although it works, there's significant latency such that I have to wait ~0.5s after pressing space before I can press any tmux hotkey for them to register correctly.
I feel like there has to be a better way to do this. Is there a way to (1) send key combinations back to the terminal from zsh natively or (2) somehow buffer any subsequent keypresses after space to wait until the osascript
command has finished executing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧...一个简单的解决方案是从命令行中使用
tmux
,直接创建我想要的命令:这没有能够正确输入前缀组合的自由,但是它获取工作完成!
Well... a simple solution is to use
tmux
from the command line and directly create the commands I want:This doesn't give the freedom of being able to properly enter the prefix combo, but it gets the job done!