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;