You're right. prompt_toolkit ignores .inputrc . There seems to be no way to define custom key bindings for vi mode in the IPython 5.0.0 profile configuration file.
Here's the workaround I'm using now. This is not very, but now it works.
According to the IPython docs, you can specify keyboard shortcuts in the startup script configuration.
Instead of binding jk to ESC , I make unicode "j" ( u'j' ) and then unicode "k" ( u'k' ) inside VimInsertMode() shortcut for prompt_toolkit , which switches to navigation mode.
I created .ipython/profile_default/startup/keybindings.py with the following code:
from IPython import get_ipython from prompt_toolkit.enums import DEFAULT_BUFFER from prompt_toolkit.filters import HasFocus, ViInsertMode from prompt_toolkit.key_binding.vi_state import InputMode ip = get_ipython() def switch_to_navigation_mode(event): vi_state = event.cli.vi_state vi_state.reset(InputMode.NAVIGATION) if getattr(ip, 'pt_cli'): registry = ip.pt_cli.application.key_bindings_registry registry.add_binding(u'j',u'k', filter=(HasFocus(DEFAULT_BUFFER) & ViInsertMode()))(switch_to_navigation_mode)
The prompt_toolkit source will help you use other shortcuts if necessary.
jellycola Aug 07 '16 at 4:12 2016-08-07 04:12
source share