Open evandrone opened 8 years ago
Hi @evandrone,
This was not obvious indeed. Your question inspired me to improve the key bindings. Now there is a new file called prompt_toolkit.key_binding.bindings.named_commands
: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/key_binding/bindings/named_commands.py
This is a start; it can be improved; but the idea is that we separate the implementation of the commands from the actual keys to which they are bound, so that it is easier to bind them to another key. Have a look at all the functions in this file, it should give you an idea of how to convert a readline config.
That's really excellent, Jonathan. Thanks! I'd started poking at key_bindings.bindings.emacs
with something similar in mind, but your solution is more complete and much appreciated. Cheers.
See also: #56 "detect key-bindings from .inputrc"
A follow up related question: inputrc allows for assigning custom terminal codes to actions, e.g.: "\e[255;3u": kill-word
How can this be achieved in prompt-toolkit?
The keybinding example shows how to do some fancy things with key bindings (CtrlT to print "hello world"), so it's clear how to execute an arbitrary callable for a given key combination (or at least, for key combinations defined in from
prompt_toolkit.keys.Keys
), but if I just want to customize key combinations for existing cursor functions, where would I go? For instance, my.inputrc
contains:The prompt-toolkit alternative should be something like:
I'd be happy to add something like this to the keybinding example, if someone can tell me what functions to call. Cheers!