问题
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