Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Keybindings for Ipython terminal

Is it possible to define custom keybindings and/or desactivate the default ones for Ipython terminal interface?

For example, I have bound C+j and C+l to move left and right in my terminal by configuring the ~/.inputrc file (Linux), but when using Ipython terminal, C+l is captured before and actually clears the screen.

So my questions are:

1) Is it possible to desactivate some keybindings of Ipython

2) Even better, is it possible to totally configure Ipython keymap?

like image 456
Antoine Gallix Avatar asked Mar 11 '26 21:03

Antoine Gallix


2 Answers

Reposting as an answer:

You can set InteractiveShell.readline_parse_and_bind in a config file (default value is here). It takes a list of readline config commands.

IPython also uses .inputrc, but things in that config value take precendence, and Ctrl+L is in there by default.

like image 148
Thomas K Avatar answered Mar 14 '26 11:03

Thomas K


For newer versions of IPython, TerminalInteractiveShell.shortcuts handles adds/changes to keybinds.

For example, to add C-] in addition to End for accepting the autocomplete suggestion, I added the following to my ipython_config.py:

c.TerminalInteractiveShell.shortcuts = [
    {
        "command": "IPython:auto_suggest.accept_or_jump_to_end",
        "new_keys": ["c-]"],
        "create": True,
    }
]
like image 30
Chris Broz Avatar answered Mar 14 '26 10:03

Chris Broz