## Summary `search::ReplaceNext` and `search::ReplaceAll` only work while focus is in the buffer search bar. Bound in the `buffer_search_deployed` context, they do nothing from the editor, unlike `search::SelectNextMatch`. Both actions are now registered for the pane, like the other search actions. Inside and outside the search bar, they run only while the replace input is visible, so a hidden replacement can't overwrite matches. Workspace-level search actions now go to the focused pane instead of the center pane, so search actions in the terminal panel no longer act on the editor's search bar. `Workspace::focused_pane` now also finds zoomed dock panels, which render outside their dock. The debug panel has no `Panel::pane`, so its Terminal tab still sends them to the editor's search bar, as on `main`. With vim mode on, `vim::SearchSubmit` now propagates when the focused pane has no vim editor or does not contain the focus, so `enter` selects the next match in the search bars of the terminal panel and the debugger's Terminal tab. Closes #66518 ## Testing - To reproduce, bind `ctrl-r` to `search::ReplaceNext` in the `buffer_search_deployed` context, open the search bar in replace mode, fill in both fields, focus the editor, and press `ctrl-r`. Nothing happens. - Tested on Linux. On `main`, neither action changes the buffer. On this branch, `search::ReplaceNext` replaces one match per press and `search::ReplaceAll` replaces the rest. - The test dispatches both actions from the editor, from the search bar with the replace input hidden, and from a docked and a zoomed panel with its own pane and a panel without one, then checks the buffer text and the replace toggle. - Each part of `test_replace_with_editor_focused` fails without its fix. - `test_search_submit_without_vim_editor` presses `enter` in the search bar of an editor without vim and checks that the next match is selected. It fails without the fix. - `test_search_submit_outside_pane` does the same in a search bar outside the panes, with a vim editor in the center pane. It fails without the focus check. - `cargo test -p search -p workspace -p file_finder -p terminal_view -p vim --lib` and `./script/clippy -p search -p workspace -p vim` pass. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - Fixed `search::ReplaceNext` and `search::ReplaceAll` doing nothing when the editor is focused while the buffer search bar is open, search actions in the terminal panel acting on the editor's search bar, and `enter` not selecting the next match in terminal search bars with Vim mode on https://github.com/user-attachments/assets/69be3dc7-9fb7-4c45-9aea-e6799db9725d --------- Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This contains the code for Zed's Vim emulation mode.
Vim mode in Zed is supposed to primarily "do what you expect": it mostly tries to copy vim exactly, but will use Zed-specific functionality when available to make things smoother. This means Zed will never be 100% vim compatible, but should be 100% vim familiar!
The backlog is maintained in the #vim channel notes.
Testing against Neovim
If you are making a change to make Zed's behavior more closely match vim/nvim, you can create a test using the NeovimBackedTestContext.
For example, the following test checks that Zed and Neovim have the same behavior when running * in visual mode:
#[gpui::test]
async fn test_visual_star_hash(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state("ˇa.c. abcd a.c. abcd").await;
cx.simulate_shared_keystrokes(["v", "3", "l", "*"]).await;
cx.assert_shared_state("a.c. abcd ˇa.c. abcd").await;
}
To keep CI runs fast, by default the neovim tests use a cached JSON file that records what neovim did (see crates/vim/test_data), but while developing this test you'll need to run it with the neovim flag enabled:
cargo test -p vim --features neovim test_visual_star_hash
This will run your keystrokes against a headless neovim and cache the results in the test_data directory. Note that neovim must be installed and reachable on your $PATH in order to run the feature.
Testing zed-only behavior
Zed does more than vim/neovim in their default modes. The VimTestContext can be used instead. This lets you test integration with the language server and other parts of zed's UI that don't have a NeoVim equivalent.