Ctrl-enter for fish shell

1

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?

Michael

Posted 2016-03-23T17:52:17.997

Reputation: 215

Answers

1

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.

Kurtis Rader

Posted 2016-03-23T17:52:17.997

Reputation: 919

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 – 2016-06-22T04:40:44.283

0

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'

Hastur

Posted 2016-03-23T17:52:17.997

Reputation: 15 043

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 – 2016-03-24T18:59:25.670

@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 – 2016-03-24T19:48:31.903

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 – 2016-03-24T20:32:15.570

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 – 2016-03-24T21:02:26.730

Downvote without any comment IMHO are useless... At least let us know what do you think is wrong or unclear... – Hastur – 2016-06-22T14:58:25.163