prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.24k stars 283 forks source link

customize keybindings #378

Open antoine-gallix opened 4 years ago

antoine-gallix commented 4 years ago

Is there an easy way to configure keybindings? I cannot find it in the documentation. I'm referring to a way to map key combinations to things like cursor movements, line edition, history.

BioBox commented 2 years ago

Yeah, no. It's not even really an issue with ptpython. Like you I desire to give the user the ability to remap the keybindings but they are hardcoded into the prompt-toolkit package using decorators to local functions that can't be accessed outside load_vi_bindings.

However, it should be possible to move these functions to a more global scope, then you can call the remove method for the default key(s) and add in what you want.

BioBox commented 2 years ago

Actually, after thinking some consideration you're honestly better off patching load_vi_bindings yourself and installing the package locally. Each binding is an immutable object bound to a private function, so to make the core vi keys "truly" remappable one would have to completely refactor its internals, or write a method that removes the conflict and appends a new one, but that'll engender some headaches for sure. Not worth it.

I'll make myself a colemak patch.

antoine-gallix commented 2 years ago

thanks for the update. on my side I've solved the problem with a programmable keyboard, so I just put the standard bindings of every program under my finger once and for all. I only cry a bit when I'm forced to work on my laptop sometimes. I've tried for years to systematically remap all the programs I use into a consistent system, ergonomic and compatible with my exotic keyboard mapping but it's hard work.