How to bind Ctrl-Enter in fish?

风格不统一 提交于 2019-12-24 06:23:11

问题


In order to configure a user binding (version 2.2.0), it must be in the fish_user_key_bindings function:

function fish_user_key_bindings
    bind \n 'commandline -f accept-autosuggestion execute'
end

This works fine.

I wanted to expand this binding to Ctrl+Enter, by using the appropriate modifier:

function fish_user_key_bindings
    bind \c\n 'commandline -f accept-autosuggestion execute'
end

This does not work: Enter uses the current (up to the cursor) suggestion (which is the default) but Ctrl+Enter as well (as if the action with the modifier was not taken into account)


回答1:


Binding \c\n doesn't make any sense because \n is already a control character. Applying the control modifier a second time to a control character has no effect. Since \n is just an alias for \cJ what you're trying to do is the equivalent of binding to \c\cJ. The only way to bind [Ctrl][Enter] is to configure your terminal to send a unique sequence for that key combination.

P.S., If you grab the current git head source you can make fish_key_reader to build a handy program which will show you a lot of information about what different keys send (although you'll need to wait a few minutes from the time I type this because I need to merge https://github.com/fish-shell/fish-shell/pull/3012).

P.P.S., As of fish 2.3.0 (currently in beta testing) the tty driver no longer automatically converts the \r (aka \cM) that the enter key sends to \n (aka \cJ).




回答2:


I think you want the following:

bind \cf accept-autosuggestion execute

or the following if you have vi mode installed

bind -M insert \cf accept-autosuggestion execute


来源:https://stackoverflow.com/questions/37114257/how-to-bind-ctrl-enter-in-fish

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!