I am writing a *nix shell, I want support the key-combination of Ctrl-Enter. And the library I use is GNU readline.
I have spent several hours on it, but can't find the way.
I can bind Enter successfully, like:
========= ~/.inputrc ===============
"\C-M": "sdf"
====================================
When I press Enter, I got "sdf" echoed, just as expected.
I can also bind Esc,Enter successfully(note, here is key serial, not combination), like:
========= ~/.inputrc ===============
"\e\C-M": "sdf"
====================================
When I pressed Esc and then pressed Enter, "sdf" was echoed as expected.
However, the following line can not produce a valid Ctrl-Enter combination:
========= ~/.inputrc ===============
"\C\C-M": "sdf"
====================================
And, "\C-\C-M" doesn't work too.
Here are two related questions:
how to bind the 'Enter key'
How to bind Ctrl-Enter in fish?
Can any one help me ?
You don't mention which terminal emulator you use - which matters, because in the end, it is the terminal that decides what your program reads from it when you press CTRL+ENTER
A way to make this work is (assuming you use xterm):
Make xterm send e.g. CTRL+k when you press CTRL+ENTER, by adding a line in your .Xdefaults:
XTerm.vt100.translations: #override Ctrl<Key>Return: string("\013")
Bind this to whatever you want in .inputrc:
"\C-k": "sdf"
Not very elegant, as this will only work in xterm. But, as far as i can see, the only way to get what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With