I understand that because Ipython 5.0.0 uses a new input library (prompt_toolkit) it no longer defaults to the editor mode specified in .inputrc (*nix). This option has to be set in an Ipython profile configuration file (see https://stackoverflow.com/a/38329940/2915339).
My question is: having set vi-mode in the profile configuration file, how does one specify a particular keybinding? I like to use 'jk' for escape, for instance.
This is an old post but it helped me find my answer so I thought I would post how I added a couple of bindings to vi mode in ipython. I added the following code in ~/.ipython/profile_default/startup/00-keybindings.py to bind to K and J in vi navigation mode.
You're right.
prompt_toolkit
ignores.inputrc
. There does not seem to be a way to define custom keybindings for thevi
mode in the IPython 5.0.0 profile configuration file.Here's workaround I'm currently using. It's not pretty, but it works for now.
According to the IPython docs, you can specify Keyboard Shortcuts in a startup configuration script.
Instead of rebinding
jk
toESC
, I'm making a unicode "j" (u'j'
) followed by a unicode "k" (u'k'
) inside ofVimInsertMode()
a shortcut for aprompt_toolkit
event that switches to navigation mode.I created a
.ipython/profile_default/startup/keybindings.py
with the following code:The prompt_toolkit source will help you implement other shortcuts as needed.