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

2024-02-14

Zsh 对于 Man 有以下键盘快捷键

Esc+h

我想要一个类似的键盘快捷键来获取信息,例如

Esc+i

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


这应该可以解决问题:

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 即可获得永久效果。

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.

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Zsh 中为 Info 创建键盘快捷键? 的相关文章

随机推荐