Skip to content

Commit 39b67d6

Browse files
bobbydavidmarijnh
authored andcommitted
[vim bindings] Add proper emulation for forward-delete
In Vim's command mode, forward-delete (Delete on PC or fn-delete on Mac) should behave the same as 'x': delete the character under the cursor. Due to a bug in CodeMirror's emulation, this wasn't happening before. This change adds the proper support, along with tests for forward-delete.
1 parent 1f82eed commit 39b67d6

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

keymap/vim.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
{ keys: '<Down>', type: 'keyToKey', toKeys: 'j' },
5454
{ keys: '<Space>', type: 'keyToKey', toKeys: 'l' },
5555
{ keys: '<BS>', type: 'keyToKey', toKeys: 'h', context: 'normal'},
56+
{ keys: '<Del>', type: 'keyToKey', toKeys: 'x', context: 'normal'},
5657
{ keys: '<C-Space>', type: 'keyToKey', toKeys: 'W' },
5758
{ keys: '<C-BS>', type: 'keyToKey', toKeys: 'B', context: 'normal' },
5859
{ keys: '<S-Space>', type: 'keyToKey', toKeys: 'w' },

test/vim_test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,31 @@ testVim('i_overwrite_backspace', function(cm, vim, helpers) {
15231523
helpers.assertCursorAt(Pos(0, 9, "after"));
15241524
eq('0123456789', cm.getValue());
15251525
}, { value: '0123456789'});
1526+
testVim('i_forward_delete', function(cm, vim, helpers) {
1527+
cm.setCursor(0, 3);
1528+
helpers.doKeys('i');
1529+
helpers.doInsertModeKeys('Delete');
1530+
helpers.assertCursorAt(0, 3);
1531+
eq('A124\nBCD', cm.getValue());
1532+
helpers.doInsertModeKeys('Delete');
1533+
helpers.assertCursorAt(0, 3);
1534+
eq('A12\nBCD', cm.getValue());
1535+
helpers.doInsertModeKeys('Delete');
1536+
helpers.assertCursorAt(0, 3);
1537+
eq('A12BCD', cm.getValue());
1538+
}, { value: 'A1234\nBCD'});
1539+
testVim('forward_delete', function(cm, vim, helpers) {
1540+
cm.setCursor(0, 3);
1541+
helpers.doInsertModeKeys('Delete');
1542+
helpers.assertCursorAt(0, 3);
1543+
eq('A124\nBCD', cm.getValue());
1544+
helpers.doInsertModeKeys('Delete');
1545+
helpers.assertCursorAt(0, 2);
1546+
eq('A12\nBCD', cm.getValue());
1547+
helpers.doInsertModeKeys('Delete');
1548+
helpers.assertCursorAt(0, 1);
1549+
eq('A1\nBCD', cm.getValue());
1550+
}, { value: 'A1234\nBCD'});
15261551
testVim('A', function(cm, vim, helpers) {
15271552
helpers.doKeys('A');
15281553
helpers.assertCursorAt(0, lines[0].length);

0 commit comments

Comments
 (0)