Skip to content

search backwards by default #10075

Closed
Closed

Description

@altaurog

With ipython 5.1.0/prompt-toolkit 1.0.9 using the vi keybindings, Esc-/ initiates a forward search. What exactly is the use case for that, and in what situation would such a search find anything? This is not the readline behavior, and therefore this is completely unlike the behavior in bash, prior versions of ipython, or pretty much any other REPL anyone would have used.
I actually thought the search was broken until I discovered that Esc-? initiates a backward search, which is what I really want. It just happens to be that's a more awkward keystroke and it's going against many years of habit.
I can't imagine other people don't find this super frustrating as well, so I'm surprised I didn't find mention of this in any other issue. Unless there's a really compelling case for the current behavior, I suggest that it be reverted.
At the very least, I would like to know if there's a way to rebind the key strokes locally so I can fix this at least on my present installation.

Activity

  1. takluyver commented on Dec 5, 2016

    @takluyver
    Member

    @jonathanslenders ? It might just be an oversight.

    You can customise the keyboard shortcuts as described here, but for now you'll need to search through prompt_toolkit source code to find what function it needs to call.

  2. altaurog commented on Dec 5, 2016

    @altaurog
    Author

    Thanks. I see. That was what I needed to get me pointed in the right direction. Shall I move this issue to the prompt_toolkit repo?

  3. takluyver commented on Dec 5, 2016

    @takluyver
    Member

    I don't think IPython defines any shortcuts specific to vim mode, so this is probably in prompt_toolkit. Jonathan often responds quickly when we ping him, though. So I'd suggest you give it a day or two, and if he doesn't say anything, re-file it on PT.

  4. altaurog commented on Dec 5, 2016

    @altaurog
    Author

    This seems to do the trick. It retrieves the bound functions for '/' and '?' and switches them.

    from IPython import get_ipython
    from prompt_toolkit.filters import ViSelectionMode, ViNavigationMode, ViMode
    
    ip = get_ipython()
    mode = (ViNavigationMode() | ViSelectionMode()) & ViMode()
    
    if getattr(ip, 'pt_cli'):
        registry = ip.pt_cli.application.key_bindings_registry
        is_search = lambda b: b.filter == mode
        forward = filter(is_search, registry.get_bindings_for_keys('/'))
        backward = filter(is_search, registry.get_bindings_for_keys('?'))
        for b in backward:
            registry.remove_binding(b.handler)
            registry.add_binding('/', filter=mode, eager=b.eager,
                                 save_before=b.save_before)(b.handler)
        for b in forward:
            registry.remove_binding(b.handler)
            registry.add_binding('?', filter=mode, eager=b.eager,
                                 save_before=b.save_before)(b.handler)
    
  5. jonathanslenders commented on Dec 5, 2016

    @jonathanslenders
    Contributor

    Hi @altaurog,

    For this, I copied the behaviour of Vi. The reason is that we support multiline editing. So, if you're at the start of a multiline buffer, then you could use forward search to jump forward. In a block of multiline text, you'll get more of the Vi feel, rather than a readline feeling.

    But maybe you're right. It could make sense to follow GNU readline, and use question mark to search forward.

    Could you open an issue in prompt_toolkit? Maybe I could make this easier to configure, or if I feel that everyone thinks it should be like readline, then I could reverse it.

  6. ndronen commented on Dec 10, 2016

    @ndronen

    Multiline editing is a very nice feature. As a longtime vim and bash user, though, the switch to IPython 5.x and prompt_toolkit has been jarring. I would much prefer that vi-mode in prompt_toolkit behaved like it does in GNU readline.

    I've opened prompt-toolkit/python-prompt-toolkit#431 to move the discussion over there.

  7. jonathanslenders commented on Dec 11, 2016

    @jonathanslenders
    Contributor

    @ndronen. I completely understand it. Thanks a lot for opening the issue!

  8. added this to the no action milestone on Jan 12, 2017
  9. takluyver commented on Jan 12, 2017

    @takluyver
    Member

    I see that this has been changed in prompt_toolkit, so when PT 1.0.10 or greater is released, it should be fixed in IPython without needing any change from us.

  10. ivanov commented on May 17, 2017

    @ivanov
    Member

    I just want to mention that if you would like the old (IPython <= 4.x) readline interface, it is now available separately as rlipython.

    pip install rlipython
    python -c "import rlipython as r; r.install()"
    

    Right now, it only works in IPython 6.0 (Python 3), but it will also work in Python 2 with the next IPython 5 release (5.4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions