From 5f7189e5af607241723bea15538ba585f9597c9f Mon Sep 17 00:00:00 2001 From: AidanV <84053180+AidanV@users.noreply.github.com> Date: Thu, 17 Apr 2025 19:51:24 -0700 Subject: [PATCH] vim: Change line up and change line down respect indentation (#28934) When using 'c' with line-wise motions like j/k, operate like cc to fix indentation issues. Closes #28933 Release Notes: - `c j` and `c k` now respect indentation --- crates/vim/src/normal/change.rs | 23 ++++++++++++++++++++++- crates/vim/test_data/test_change_j.json | 4 ++++ crates/vim/test_data/test_change_k.json | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/normal/change.rs b/crates/vim/src/normal/change.rs index 7e27cda949707d40c4aeb9fce635091f42a5e378..e6ecf309f198891ba05370a9270d52978c73ea52 100644 --- a/crates/vim/src/normal/change.rs +++ b/crates/vim/src/normal/change.rs @@ -62,7 +62,10 @@ impl Vim { &text_layout_details, forced_motion, ); - if let Motion::CurrentLine = motion { + if matches!( + motion, + Motion::CurrentLine | Motion::Down { .. } | Motion::Up { .. } + ) { let mut start_offset = selection.start.to_offset(map, Bias::Left); let classifier = map @@ -422,6 +425,15 @@ mod test { ) .await .assert_matches(); + cx.simulate( + "c k", + indoc! {" + The quick + brown fox + ˇjumps over"}, + ) + .await + .assert_matches(); } #[gpui::test] @@ -463,6 +475,15 @@ mod test { ) .await .assert_matches(); + cx.simulate( + "c j", + indoc! {" + The quick + ˇbrown fox + jumps over"}, + ) + .await + .assert_matches(); } #[gpui::test] diff --git a/crates/vim/test_data/test_change_j.json b/crates/vim/test_data/test_change_j.json index 827fe18c0dbaf0dc15e55a4036d8961b625bc9b1..3808bb21e21ede54051e13f9d790c6f3a5107559 100644 --- a/crates/vim/test_data/test_change_j.json +++ b/crates/vim/test_data/test_change_j.json @@ -14,3 +14,7 @@ {"Key":"c"} {"Key":"j"} {"Get":{"state":"The quick\nbrown fox\nˇ","mode":"Normal"}} +{"Put":{"state":"The quick\n ˇbrown fox\n jumps over"}} +{"Key":"c"} +{"Key":"j"} +{"Get":{"state":"The quick\n ˇ","mode":"Insert"}} diff --git a/crates/vim/test_data/test_change_k.json b/crates/vim/test_data/test_change_k.json index 4f89a82b80a6149f97122f21f11435598ca3a7fb..5ac92744d14f546989c781d4de8bfb2fde398b7e 100644 --- a/crates/vim/test_data/test_change_k.json +++ b/crates/vim/test_data/test_change_k.json @@ -14,3 +14,7 @@ {"Key":"c"} {"Key":"k"} {"Get":{"state":"ˇ\nbrown fox\njumps over","mode":"Normal"}} +{"Put":{"state":"The quick\n brown fox\n ˇjumps over"}} +{"Key":"c"} +{"Key":"k"} +{"Get":{"state":"The quick\n ˇ","mode":"Insert"}}