在 Zsh 中为 Info 创建键盘快捷键?

发布于 2024-07-18 19:59:50 字数 174 浏览 2 评论 0原文

有以下键盘快捷键,

Zsh 对于 Man Esc+h

我希望有一个类似的键盘快捷键,用于诸如

Esc+ 等信息i

如何为信息制作这样的键盘快捷键?

Zsh has the following keyboard shortcut for Man

Esc+h

I would like to have a similar keyboard shortcut for info such as

Esc+i

How can you make such a keyboard shortcut for Info?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-07-25 19:59:50

这应该可以解决问题:

function run_info() { 
  # Prepend "info" to the command line and run it.
  BUFFER="info $BUFFER"
  zle accept-line
}

# Define a widget called "run_info", mapped to our function above.
zle -N run_info

# Bind it to ESC-i.
bindkey "^[i" run_info

只需将其剪切并粘贴到 shell 中进行尝试,然后添加到您的 .zshrc 以获得永久效果。

解释一下代码:总体思路是我们首先定义一个名为“run_info”的小部件,用同名的函数实现。 它获取命令行缓冲区并在开头添加“info”。 然后它接受命令行(与按 Enter 相同)。 最后,小部件被映射到键盘快捷键。

您可以阅读 zshzle(1) 手册页以获取有关此内容如何工作的更多信息。

This should do the trick:

function run_info() { 
  # Prepend "info" to the command line and run it.
  BUFFER="info $BUFFER"
  zle accept-line
}

# Define a widget called "run_info", mapped to our function above.
zle -N run_info

# Bind it to ESC-i.
bindkey "^[i" run_info

Just cut'n paste that into a shell to try it out, and add to your .zshrc for permanent effect.

To paraphrase the code: the general idea is that we first define a widget called "run_info", implemented with a function with the same name. It takes the command line buffer and adds "info " to the beginning. Then it accepts the command line (same as pressing Enter). Finally, the widget is mapped to the keyboard shortcut.

You can read the zshzle(1) man page for more info on how this stuff works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文