fish 文档说您可以使用语法运行命令列表
bind <char> cmd1 cmd2 ...
包括https://fishshell.com/docs/current/commands.html#bind中列出的一些特殊命令.
编写具有键绑定(bind)的插件,
我添加
bind '&' `backward-delete-char` on_ampersand
至fish_user_key_bindings.fish
,但它没有导致任何行为 - on_ampersand
函数没有被调用,backward_delete_char
也没有被调用。 。没有on_ampersand
, 有用。
文档没有说明为什么会发生这种行为。
最佳答案
这是 Fish 中的一个错误 - 您无法将输入缓冲区编辑命令与您自己的命令结合起来。请参阅https://github.com/fish-shell/fish-shell/issues/3683 .
解决方法是在用户定义的函数中使用命令行 -f [function]
语法来访问那些专门供 fish_user_key_bindings
使用的函数:
function on_ampersand
commandline -f backward-delete-char # or whatever
[your code]
end
关于fish - `bind` 不运行用户定义函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45533272/