vim: Add neovim 0.11 default mappings (#28602)

Update the keymap to include:
https://neovim.io/doc/user/news-0.11.html#_defaults

This does conflict with `gr` replace with register though, is `gR` a
good alternative?

Release Notes:

- vim: Update the keymap to include: https://neovim.io/doc/user/news-0.11.html#_defaults
- vim: Replace with register has been remapped from `gr` to `gR`.
This commit is contained in:
5brian 2025-04-28 14:14:43 -04:00 committed by GitHub
parent b41ffae161
commit ed367e1636
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 134 additions and 13 deletions

View file

@ -43,6 +43,8 @@ actions!(
InsertEndOfLine,
InsertLineAbove,
InsertLineBelow,
InsertEmptyLineAbove,
InsertEmptyLineBelow,
InsertAtPrevious,
JoinLines,
JoinLinesNoWhitespace,
@ -72,6 +74,8 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, Vim::insert_end_of_line);
Vim::action(editor, cx, Vim::insert_line_above);
Vim::action(editor, cx, Vim::insert_line_below);
Vim::action(editor, cx, Vim::insert_empty_line_above);
Vim::action(editor, cx, Vim::insert_empty_line_below);
Vim::action(editor, cx, Vim::insert_at_previous);
Vim::action(editor, cx, Vim::change_case);
Vim::action(editor, cx, Vim::convert_to_upper_case);
@ -537,6 +541,61 @@ impl Vim {
});
}
fn insert_empty_line_above(
&mut self,
_: &InsertEmptyLineAbove,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.record_current_action(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
editor.transact(window, cx, |editor, _, cx| {
let selections = editor.selections.all::<Point>(cx);
let selection_start_rows: BTreeSet<u32> = selections
.into_iter()
.map(|selection| selection.start.row)
.collect();
let edits = selection_start_rows
.into_iter()
.map(|row| {
let start_of_line = Point::new(row, 0);
(start_of_line..start_of_line, "\n".to_string())
})
.collect::<Vec<_>>();
editor.edit(edits, cx);
});
});
}
fn insert_empty_line_below(
&mut self,
_: &InsertEmptyLineBelow,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.record_current_action(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
editor.transact(window, cx, |editor, _, cx| {
let selections = editor.selections.all::<Point>(cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);
let selection_end_rows: BTreeSet<u32> = selections
.into_iter()
.map(|selection| selection.end.row)
.collect();
let edits = selection_end_rows
.into_iter()
.map(|row| {
let end_of_line = Point::new(row, snapshot.line_len(MultiBufferRow(row)));
(end_of_line..end_of_line, "\n".to_string())
})
.collect::<Vec<_>>();
editor.edit(edits, cx);
});
});
}
fn join_lines_impl(
&mut self,
insert_whitespace: bool,
@ -1267,6 +1326,31 @@ mod test {
);
}
#[gpui::test]
async fn test_insert_empty_line_above(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate("[ space", "ˇ").await.assert_matches();
cx.simulate("[ space", "The ˇquick").await.assert_matches();
cx.simulate_at_each_offset(
"[ space",
indoc! {"
The qˇuick
brown ˇfox
jumps ˇover"},
)
.await
.assert_matches();
cx.simulate(
"[ space",
indoc! {"
The quick
ˇ
brown fox"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_dd(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

View file

@ -917,7 +917,7 @@ mod test {
);
cx.simulate_keystrokes("y i w");
cx.simulate_keystrokes("w");
cx.simulate_keystrokes("g r i w");
cx.simulate_keystrokes("g shift-r i w");
cx.assert_state(
indoc! {"
fish fisˇh
@ -925,7 +925,7 @@ mod test {
"},
Mode::Normal,
);
cx.simulate_keystrokes("j b g r e");
cx.simulate_keystrokes("j b g shift-r e");
cx.assert_state(
indoc! {"
fish fish
@ -945,7 +945,7 @@ mod test {
);
cx.simulate_keystrokes("y i w");
cx.simulate_keystrokes("w");
cx.simulate_keystrokes("v i w g r");
cx.simulate_keystrokes("v i w g shift-r");
cx.assert_state(
indoc! {"
fish fisˇh
@ -953,7 +953,7 @@ mod test {
"},
Mode::Normal,
);
cx.simulate_keystrokes("g r r");
cx.simulate_keystrokes("g shift-r r");
cx.assert_state(
indoc! {"
fisˇh
@ -961,7 +961,7 @@ mod test {
"},
Mode::Normal,
);
cx.simulate_keystrokes("j w g r $");
cx.simulate_keystrokes("j w g shift-r $");
cx.assert_state(
indoc! {"
fish
@ -986,7 +986,7 @@ mod test {
);
cx.simulate_keystrokes("y i w");
cx.simulate_keystrokes("w");
cx.simulate_keystrokes("g r i w");
cx.simulate_keystrokes("g shift-r i w");
cx.assert_state(
indoc! {"
fish fisˇh

View file

@ -954,7 +954,7 @@ impl Operator {
Operator::AutoIndent => "eq",
Operator::ShellCommand => "sh",
Operator::Rewrap => "gq",
Operator::ReplaceWithRegister => "gr",
Operator::ReplaceWithRegister => "gR",
Operator::Exchange => "cx",
Operator::Outdent => "<",
Operator::Uppercase => "gU",

View file

@ -0,0 +1,24 @@
{"Put":{"state":"ˇ"}}
{"Key":"["}
{"Key":"space"}
{"Get":{"state":"\nˇ","mode":"Normal"}}
{"Put":{"state":"The ˇquick"}}
{"Key":"["}
{"Key":"space"}
{"Get":{"state":"\nThe ˇquick","mode":"Normal"}}
{"Put":{"state":"The qˇuick\nbrown fox\njumps over"}}
{"Key":"["}
{"Key":"space"}
{"Get":{"state":"\nThe qˇuick\nbrown fox\njumps over","mode":"Normal"}}
{"Put":{"state":"The quick\nbrown ˇfox\njumps over"}}
{"Key":"["}
{"Key":"space"}
{"Get":{"state":"The quick\n\nbrown ˇfox\njumps over","mode":"Normal"}}
{"Put":{"state":"The quick\nbrown fox\njumps ˇover"}}
{"Key":"["}
{"Key":"space"}
{"Get":{"state":"The quick\nbrown fox\n\njumps ˇover","mode":"Normal"}}
{"Put":{"state":"The quick\nˇ\nbrown fox"}}
{"Key":"["}
{"Key":"space"}
{"Get":{"state":"The quick\n\nˇ\nbrown fox","mode":"Normal"}}