From a0e666ae930a85ab38947e2d49222b0ea99f1c2f Mon Sep 17 00:00:00 2001 From: Corentin Hervaud Date: Thu, 26 Nov 2026 16:56:47 +0000 Subject: [PATCH] vim: Show yank highlight in characterwise visual mode (#67158) ## Summary Closes #67153 Yanking in characterwise visual mode (`v` + `y`) never showed the yank highlight, while visual line (`V`), visual block (`ctrl-v`) and normal-mode yanks did. The cause was an early return in `Vim::copy_ranges` that only checked `Mode::Visual`, so `Mode::VisualLine` and `Mode::VisualBlock` were highlighted anyway. This remove the `Mode::Visual` check so every yank is highlighted, as long as `vim.highlight_on_yank_duration` is not `0`. This matches Neovim's `vim.highlight.on_yank`, which highlights visual yanks by default (`on_visual = true`). The highlight also confirms that the yank happened, since the selection disappears either way. | Before | After | |-|-| | https://github.com/user-attachments/assets/04aba5a0-3082-4fd1-872d-2968cab88058 | https://github.com/user-attachments/assets/1f243f2e-36bd-489f-87d9-07087fc53f35 | ## Testing - Added `test_highlight_on_yank_in_visual_modes`, which checks the yank highlight in characterwise, linewise and blockwise visual mode, and that the highlight is cleared after `hightlight_on_yank_duration`. The test fails without the fix. - `cargo test -p vim --lib`: all tests pass. - `./script/clippy -p vim`: no warnings. - Manually tested on MacOS (see recordings above). ## 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 the vim yank highlight not showing when yanking in characterwise visual mode. --------- Co-authored-by: Claude Co-authored-by: Smit Barmase --- crates/vim/src/normal/yank.rs | 2 +- crates/vim/src/visual.rs | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/normal/yank.rs b/crates/vim/src/normal/yank.rs index 6f2abfddd57..5ff3f2a08d2 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -221,7 +221,7 @@ impl Vim { }); let highlight_duration = VimSettings::get_global(cx).highlight_on_yank_duration; - if !is_yank || self.mode == Mode::Visual || highlight_duration == 0 { + if !is_yank || highlight_duration == 0 { return; } diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs index a27d0c2ec2a..97046dedeb3 100644 --- a/crates/vim/src/visual.rs +++ b/crates/vim/src/visual.rs @@ -945,10 +945,15 @@ impl Vim { } #[cfg(test)] mod test { + use std::time::Duration; + + use editor::HighlightKey; use indoc::indoc; + use settings::Settings as _; use workspace::item::Item; use crate::{ + VimSettings, state::Mode, test::{NeovimBackedTestContext, VimTestContext}, }; @@ -1305,6 +1310,59 @@ mod test { cx.shared_clipboard().await.assert_eq("fox jumps over\n"); } + #[gpui::test] + async fn test_visual_yank_highlight(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + let highlight_duration = Duration::from_millis( + cx.read(|cx| VimSettings::get_global(cx).highlight_on_yank_duration), + ); + + cx.set_state( + indoc! {" + The ˇquick brown + fox jumps over + the lazy dog"}, + Mode::Normal, + ); + cx.simulate_keystrokes("v e y"); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + The «quickˇ» brown + fox jumps over + the lazy dog"}, + ); + cx.executor().advance_clock(highlight_duration); + cx.run_until_parked(); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + The quick brown + fox jumps over + the lazy dog"}, + ); + + cx.simulate_keystrokes("V j y"); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + «The quick brown + fox jumps overˇ» + the lazy dog"}, + ); + cx.executor().advance_clock(highlight_duration); + cx.run_until_parked(); + + cx.simulate_keystrokes("ctrl-v j l y"); + cx.assert_editor_background_highlights( + HighlightKey::HighlightOnYank, + indoc! {" + «Thˇ»e quick brown + «foˇ»x jumps over + the lazy dog"}, + ); + } + #[gpui::test] async fn test_visual_block_mode(cx: &mut gpui::TestAppContext) { let mut cx = NeovimBackedTestContext::new(cx).await;