Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for history search in command-line mode #6613

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

LEI
Copy link
Contributor

@LEI LEI commented Apr 6, 2023

This is an attempt to implement "partial history search" allowing :a<Up> to show the previous entry starting with "a".

Added search for <Up>/<Down> and <C-p>/<C-n> and changed their behavior, even with no search term:

  • :<Up><Down> now goes back to the initial empty state
  • and prevent <C-n> or <Down> from cycling back to the first history entry.

The prompt value at the end of the existing history_completion test was "asdf" before but now <tab> seems to have an effect, I am guessing this test should only verify the absence of errors?

Maybe this could apply to "/" and "?" as well.

LEI added 2 commits April 6, 2023 02:03
- `:<Up><Down>` now goes back to the initial empty state
- Prevent `<C-n>`/`<Up>` from cycling back the first history entry
- Change `<Up>` and `<Down>` to only show entries starting with the prompt
  input before the cursor

TODO:
- Also replace change_history with search_history for C-n/p, option?
- Maybe add this capability to "/" and "?"
- Slim down/refactor integration tests
@pascalkuthe
Copy link
Member

It looks like you are doing a simple prefix match here. Using fuzzy matching would be preferable I think we use it for all completions (both in the editor and command mode)

@LEI
Copy link
Contributor Author

LEI commented Apr 6, 2023

How would fuzzy matching work more precisely? I would not expect :b<up> to match abc for example.

I think this is the default in Vim, and a similar keybind is possible with readline:

   history-search-backward
          Search backward through the history for the string of
          characters between the start of the current line and the
          current cursor position (the point).  The search string
          must match at the beginning of a history line.  This is a
          non-incremental search.

@the-mikedavis
Copy link
Member

Duplicate of #2796

@the-mikedavis the-mikedavis marked this as a duplicate of #2796 Apr 6, 2023
@LEI
Copy link
Contributor Author

LEI commented Apr 6, 2023

Thanks, somehow missed this! I guess the implementation is better and it applies to / & ?.
One difference being C-p and C-n both cycle instead of stopping at the first/last entry (this may be better too, I'll give it a try).

Would it help if I try to add a few integration tests to this PR (requiring visibility changes)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants