Search code examples
ipythonconfig

How to configure ipython shortcuts?


I tried adding this to my ipython config

c.TerminalInteractiveShell.shortcuts = [
    {
        "command": "IPython:auto_suggest.accept",
        "new_keys": ["c-z"],
    }
]

but then ipython complains that:

ValueError: Multiple shortcuts matching {'command': 'IPython:auto_suggest.accept'} found, please add keys/filter to select one of: [Binding(command=<function accept at 0x7f6fc3aa4ca0>, keys=['c-f'], condition='has_suggestion & default_buffer_focused & emacs_like_insert_mode'), Binding(command=<function accept at 0x7f6fc3aa4ca0>, keys=['right'], condition='has_suggestion & default_buffer_focused & emacs_like_insert_mode')]

The documentation is not exactly verbose on the topic, or I haven't found the right place to look ...


Solution

  • "for a command that already has a shortcut you need to use match_keys instead of new_keys":

    c.TerminalInteractiveShell.shortcuts = [
        {
            "command": "IPython:auto_suggest.accept",
            "match_keys": ["c-z"],
        }
    ]
    

    see: https://github.com/ipython/ipython/issues/14117