Skip to content

Change behavior of search with vim mode enabled#51073

Merged
ConradIrwin merged 6 commits intozed-industries:mainfrom
viveksjain:vim_search
Apr 1, 2026
Merged

Change behavior of search with vim mode enabled#51073
ConradIrwin merged 6 commits intozed-industries:mainfrom
viveksjain:vim_search

Conversation

@viveksjain
Copy link
Copy Markdown
Contributor

@viveksjain viveksjain commented Mar 9, 2026

When vim mode is enabled, previously if Cmd-F (or platform equivalent) was pressed, enter will go to the editor's first match, and then hitting enter again goes to the next line rather than next match. This PR changes it to make enter go to the next match, which matches the convention in most other programs. The behavior when search is initiated with / is left unchanged.

This is a reopen of #35157, rebased and fixed.
Closes #7692

Release Notes:

  • In vim mode, when search is triggered by the non-vim mode shortcut (cmd-f by default) enter will now behave as it does outside of vim mode.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 9, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 9, 2026
@ConradIrwin
Copy link
Copy Markdown
Member

@viveksjain The vim mode bool makes sense to me; but what's the show_match_highlights boolean about? Are they the same state, and if not what's the different cases it's true and false?

@viveksjain
Copy link
Copy Markdown
Contributor Author

viveksjain commented Mar 10, 2026

what's the show_match_highlights boolean about?

It's perhaps more accurate to call it select_entire_match or dont_collapse_matches, if searching with / then there is logic to collapse the match and only put the cursor on the first char. However, if using Cmd+F then the whole match is selected (and so if you then hit esc, the matched section is selected and you can edit it directly).

@ConradIrwin
Copy link
Copy Markdown
Member

@viveksjain can we use !vim_mode_search instead of having a second variable to track? I would have thought they would be the same condition

@viveksjain
Copy link
Copy Markdown
Contributor Author

Ah yes you're right, somehow I didn't realize that. Thanks for the suggestion, updated!

@viveksjain viveksjain closed this Mar 13, 2026
@viveksjain viveksjain reopened this Mar 13, 2026
@viveksjain
Copy link
Copy Markdown
Contributor Author

Whoops didn't mean to close

@viveksjain
Copy link
Copy Markdown
Contributor Author

Hi @ConradIrwin, please let me know if anything else is needed here!

@ConradIrwin
Copy link
Copy Markdown
Member

Could you please make the linter happy?

@viveksjain
Copy link
Copy Markdown
Contributor Author

I fixed the format, I'm not sure from the logs why orchestrate failed

viveksjain and others added 6 commits March 30, 2026 13:16
Fixes zed-industries#7692. When vim mode is enabled, previously if `Cmd-F` (or platform equivalent) was pressed, enter will go to the editor's first match, and then hitting enter again goes to the next line rather than next match. This PR changes it to make enter go to the next match, which matches the convention in most other programs. The behavior when search is initiated with `/` is left unchanged.
When vim mode is enabled and search is opened via Cmd-F, the current match is
now selected (and not collapsed to the first character).  Closing the search
bar preserves the selection and restores the prior mode (Visual for
Normal/Visual, Insert for Insert).
We need to collapse matches by default in vim mode, which didn't work correctly with previous approach where vim_mode_search value is false by default and thus collapse_matches was also false. This flips the parameter to cmd_f_search, which is then false by default and it makes collapse_matches true.
@viveksjain
Copy link
Copy Markdown
Contributor Author

I think I've fixed the tests now!

@ConradIrwin ConradIrwin enabled auto-merge (squash) April 1, 2026 03:48
@ConradIrwin ConradIrwin merged commit 0b275ea into zed-industries:main Apr 1, 2026
30 checks passed
@shinebayar-g
Copy link
Copy Markdown

Yo this is so much better now, thanks @viveksjain!

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

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vim mode search should act like non-Vim mode when not triggered with /

3 participants