Skip to content

Commit a173882

Browse files
nightwingmarijnh
authored andcommitted
[vim] implement gi gI gJ
1 parent 93659d9 commit a173882

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

keymap/vim.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@
164164
{ keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'eol' }, context: 'normal' },
165165
{ keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' },
166166
{ keys: 'i', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'inplace' }, context: 'normal' },
167+
{ keys: 'gi', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'lastEdit' }, context: 'normal' },
167168
{ keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'firstNonBlank'}, context: 'normal' },
169+
{ keys: 'gI', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'bol'}, context: 'normal' },
168170
{ keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'startOfSelectedArea' }, context: 'visual' },
169171
{ keys: 'o', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: true }, context: 'normal' },
170172
{ keys: 'O', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: false }, context: 'normal' },
@@ -174,6 +176,7 @@
174176
{ keys: '<C-q>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }},
175177
{ keys: 'gv', type: 'action', action: 'reselectLastSelection' },
176178
{ keys: 'J', type: 'action', action: 'joinLines', isEdit: true },
179+
{ keys: 'gJ', type: 'action', action: 'joinLines', actionArgs: { keepSpaces: true }, isEdit: true },
177180
{ keys: 'p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true }},
178181
{ keys: 'P', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true }},
179182
{ keys: 'r<character>', type: 'action', action: 'replace', isEdit: true },
@@ -2380,6 +2383,8 @@
23802383
var height = cm.listSelections().length;
23812384
if (insertAt == 'eol') {
23822385
head = Pos(head.line, lineLength(cm, head.line));
2386+
} else if (insertAt == 'bol') {
2387+
head = Pos(head.line, 0);
23832388
} else if (insertAt == 'charAfter') {
23842389
head = offsetCursor(head, 0, 1);
23852390
} else if (insertAt == 'firstNonBlank') {
@@ -2418,6 +2423,8 @@
24182423
if (vim.visualMode){
24192424
return;
24202425
}
2426+
} else if (insertAt == 'lastEdit') {
2427+
head = getLastEditPos(cm) || head;
24212428
}
24222429
cm.setOption('disableInput', false);
24232430
if (actionArgs && actionArgs.replace) {
@@ -2526,7 +2533,9 @@
25262533
var tmp = Pos(curStart.line + 1,
25272534
lineLength(cm, curStart.line + 1));
25282535
var text = cm.getRange(curStart, tmp);
2529-
text = text.replace(/\n\s*/g, ' ');
2536+
text = actionArgs.keepSpaces
2537+
? text.replace(/\n\r?/g, '')
2538+
: text.replace(/\n\s*/g, ' ');
25302539
cm.replaceRange(text, curStart, tmp);
25312540
}
25322541
var curFinalPos = Pos(curStart.line, finalCh);

test/vim_test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,13 +1608,13 @@ testVim('i_forward_delete', function(cm, vim, helpers) {
16081608
}, { value: 'A1234\nBCD'});
16091609
testVim('forward_delete', function(cm, vim, helpers) {
16101610
cm.setCursor(0, 3);
1611-
helpers.doInsertModeKeys('Delete');
1611+
helpers.doKeys('<Del>');
16121612
helpers.assertCursorAt(0, 3);
16131613
eq('A124\nBCD', cm.getValue());
1614-
helpers.doInsertModeKeys('Delete');
1614+
helpers.doKeys('<Del>');
16151615
helpers.assertCursorAt(0, 2);
16161616
eq('A12\nBCD', cm.getValue());
1617-
helpers.doInsertModeKeys('Delete');
1617+
helpers.doKeys('<Del>');
16181618
helpers.assertCursorAt(0, 1);
16191619
eq('A1\nBCD', cm.getValue());
16201620
}, { value: 'A1234\nBCD'});
@@ -1690,6 +1690,25 @@ testVim('J_repeat', function(cm, vim, helpers) {
16901690
eq(expectedValue, cm.getValue());
16911691
helpers.assertCursorAt(0, expectedValue.indexOf('word3') - 1);
16921692
}, { value: 'word1 \n word2\nword3\n word4' });
1693+
testVim('gJ', function(cm, vim, helpers) {
1694+
cm.setCursor(0, 4);
1695+
helpers.doKeys('g', 'J');
1696+
eq('word1word2 \n word3', cm.getValue());
1697+
helpers.assertCursorAt(0, 5);
1698+
helpers.doKeys('g', 'J');
1699+
eq('word1word2 word3', cm.getValue());
1700+
helpers.assertCursorAt(0, 11);
1701+
}, { value: 'word1\nword2 \n word3' });
1702+
testVim('gi', function(cm, vim, helpers) {
1703+
cm.setCursor(1, 5);
1704+
helpers.doKeys('g', 'I');
1705+
helpers.doKeys('a', 'a', '<Esc>', 'k');
1706+
eq('12\naa xxxx', cm.getValue());
1707+
helpers.assertCursorAt(0, 1);
1708+
helpers.doKeys('g', 'i');
1709+
helpers.assertCursorAt(1, 2);
1710+
eq('vim-insert', cm.getOption('keyMap'));
1711+
}, { value: '12\n xxxx' });
16931712
testVim('p', function(cm, vim, helpers) {
16941713
cm.setCursor(0, 1);
16951714
helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);

0 commit comments

Comments
 (0)