Skip to content

Filter cmdline/search history by typed text on <Up>/<Down> (#3951) - #10125

Open
MahbodHastam wants to merge 1 commit into
VSCodeVim:masterfrom
MahbodHastam:fix/cmdline-history-prefix
Open

MahbodHastam wants to merge 1 commit into
VSCodeVim:masterfrom
MahbodHastam:fix/cmdline-history-prefix

Conversation

@MahbodHastam

Copy link
Copy Markdown

What this PR does / why we need it:

In Vim, <Up>/<Down> on the command line recall only the history entries that start with what you've typed so far (:help c_<Up>), while <C-p>/<C-n> browsw history unfiltered (:help c_CTRL-P).

Changes:

  • <Up>/<Down> skip history entries that don't start with the text before the cursor. This applies to both : command history and //? search history.
  • <C-p>/<C-n> are unchanged (unfiltered), matching Vim.
  • Moving past the newest entry now restores the text you've typed. Previously it was lost because historyIndex was initialized to history.length instead of undefined, so the typed text was never saved. The existing test had a TODO for this , which is now resolved.
  • If you edit a recalled entry and press <Up> again, the edited text becomes the new prefix.

Example (from #3951): search /abc, then /def, then type /a and press <Up>. Before: /def. After: /abc

Which issue(s) this PR fixes
Fixes #3951

Special notes for your reviewer:

  • The <Up> and <C-p> actions are split into separate classes in src/actions/commands/commandLine.ts so each can pass matchPrefix.
  • Tests added in test/cmd_line/command.test.ts; the existing <C-p>/<C-n> test now asserts :w| instead of :|.

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.

Command line and search history should be filtered by what you've typed so far

1 participant