How does one set specific vim-bindings in Ipython 5.0.0

前端 未结 2 1372
后悔当初
后悔当初 2021-01-12 21:33

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 b

2条回答
  •  长发绾君心
    2021-01-12 22:08

    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.

    """Improve history access so I can skip over functions"""
    
    from IPython import get_ipython
    from prompt_toolkit.enums import DEFAULT_BUFFER
    from prompt_toolkit.filters import HasFocus, ViNavigationMode
    from prompt_toolkit.key_binding.bindings.named_commands import get_by_name
    
    ip = get_ipython()
    registry = ip.pt_app.key_bindings
    ph = get_by_name('previous-history')
    nh = get_by_name('next-history')
    registry.add_binding('K',
                         filter=(HasFocus(DEFAULT_BUFFER) &
                                 ViNavigationMode()))(ph)
    registry.add_binding('J',
                         filter=(HasFocus(DEFAULT_BUFFER) &
                                 ViNavigationMode()))(nh)
    

提交回复
热议问题