From 35477d9d99d8018e58adf40a0ba679f2fa307e82 Mon Sep 17 00:00:00 2001 From: Vivek Jain Date: Sun, 27 Jul 2025 08:09:36 -0700 Subject: [PATCH 1/2] Change behavior of search with vim mode enabled Fixes #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. --- crates/vim/src/normal/search.rs | 11 +++++++++-- crates/vim/src/state.rs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 24f2cf751f..cb830f93c7 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -192,6 +192,7 @@ impl Vim { self.search = SearchState { direction, count, + vim_mode_search: true, prior_selections, prior_operator: self.operator_stack.last().cloned(), prior_mode, @@ -230,8 +231,14 @@ impl Vim { count = count.saturating_sub(1) } self.search.count = 1; - search_bar.select_match(direction, count, window, cx); - search_bar.focus_editor(&Default::default(), window, cx); + // If search was initiated with vim shortcut '/', focus on editor, else if initiated + // via standard search shortcut, keep search bar focused (and always move by count=1). + if self.search.vim_mode_search { + search_bar.select_match(direction, count, window, cx); + search_bar.focus_editor(&Default::default(), window, cx); + } else { + search_bar.select_match(direction, 1, window, cx); + } let prior_selections: Vec<_> = self.search.prior_selections.drain(..).collect(); let prior_mode = self.search.prior_mode; diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index c4be034871..4776502baf 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -979,6 +979,7 @@ impl Clone for ReplayableAction { pub struct SearchState { pub direction: Direction, pub count: usize, + pub vim_mode_search: bool, pub prior_selections: Vec>, pub prior_operator: Option, From 55f3f6c60f05c3364b80039f777dc81040c934b1 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 14 Aug 2025 21:33:56 -0600 Subject: [PATCH 2/2] Move if statement further up --- crates/vim/src/normal/search.rs | 10 ++-------- crates/vim/src/vim.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index cb830f93c7..369f32cef3 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -231,14 +231,8 @@ impl Vim { count = count.saturating_sub(1) } self.search.count = 1; - // If search was initiated with vim shortcut '/', focus on editor, else if initiated - // via standard search shortcut, keep search bar focused (and always move by count=1). - if self.search.vim_mode_search { - search_bar.select_match(direction, count, window, cx); - search_bar.focus_editor(&Default::default(), window, cx); - } else { - search_bar.select_match(direction, 1, window, cx); - } + search_bar.select_match(direction, count, window, cx); + search_bar.focus_editor(&Default::default(), window, cx); let prior_selections: Vec<_> = self.search.prior_selections.drain(..).collect(); let prior_mode = self.search.prior_mode; diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index c747c30462..62f6a98bc3 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -336,8 +336,12 @@ pub fn init(cx: &mut App) { .and_then(|item| item.act_as::(cx)) .and_then(|editor| editor.read(cx).addon::().cloned()); let Some(vim) = vim else { return }; - vim.entity.update(cx, |_, cx| { - cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx)) + vim.entity.update(cx, |vim, cx| { + if vim.search.vim_mode_search { + cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx)) + } else { + cx.propagate() + } }) }); })