I had tried to create some accept completion and execute right away combination in fish on pressing Ctrl+Enter.

function fish_user_key_bindings
    bind \c\n accept-autosuggestion execute
end

Unfortunately this attempt fails. Looks like fish doesn't like two escaped chars:

#bind -a
...
bind \\c\\n accept-autosuggestion execute

Any better ideas?

Binding ctrl+enter doesn't make any sense. The enter key normally sends a carriage-return; \r, aka \cM. In other words, enter is already a control character. So applying the \c modifier does’t make any sense. In fact, this should cause Fish to generate an error so I’ll open an issue to remind the team to fix that.

Also, you were trying to bind \c\n. Binding \n (aka \cJ) works for Fish 2.2.0 or earlier. But as of 2.3.0 you won’t get the expected result because fish now disables the TTY driver’s icrnl mode. So Fish will receive the \r (aka \cM) character normally sent by the enter key. So you really want to bind \r (or \cM). Of course that doesn’t change the fact that that \c\cM doesn’t make any sense.

  • Github issue 3162 opened to track enhancing fish to warn about doing non-sensical things like applying the \c modifier to a control character. – Kurtis Rader Jun 22 '16 at 4:40

Probably you missed only the '' in the bind command line.

Indeed the simple bind \c\n accept-autosuggestion execute generates the error:

bind: Expected zero or two parameters, got 3

Adding '' around the command it seems to works

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

After the bind command execution with bind -a gives me

bind \x1cn 'accept-autosuggestion execute'

  • Well, just try it without the execute in the end. Ctrl-return is just not recognized that way, whatever you put in the end. Also quoting \c\n is of no help. And when I just pick any other combination, e.g. \cn, it also works without quoting the both commands. – Michael Mar 24 '16 at 18:59
  • @Michael I needed to quote the composite command because bind wants 0 or 2 parameters and when 2, the second is the action. You can check in bind -a. I cannot answer now if you can bind ctrl enter. I tried to bind as action 'echo ; echo ; echo ' to ctrl-a and it works. Please add the version of fish you are using... – Hastur Mar 24 '16 at 19:48
  • I'm using 2.2.0. Again, \cn or \ca whatever, works fine for me, using qouting for the commands or not, the command is executed. Maybe your version is outdated here? Anyways, binding ctrl-a and referring to that is pointless, I'm specifically talking about \c\n. – Michael Mar 24 '16 at 20:32
  • I'm using the last available for Ubuntu LTS (the 2.0.0) updated and installed this morning just for your question. BTW the problem with <Ctrl-Enter> is that it depends on the terminal you are using: some terminals send <NL> when <C-Enter> is pressed. Some others < ^M> as for the simple <Enter>. See 1 and 2. Check your terminal, maybe inside a bash with <Ctrl-V> and after <Enter> and <Ctrl-Enter> – Hastur Mar 24 '16 at 21:02
  • Downvote without any comment IMHO are useless... At least let us know what do you think is wrong or unclear... – Hastur Jun 22 '16 at 14:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.