Skip to content

Commit 9a40f56

Browse files
mattsacksmarijnh
authored andcommitted
Refactor the Shift-D keymapping for vim
Before, Shift-D would delete the entire line with the vim keymapping set. Vim's binding for this deletes from the cursor up til the end of the line, so that's been fixed. Also, allow for count iterations on Shift-D.
1 parent 7b6c49b commit 9a40f56

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

keymap/vim.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,26 @@
324324
},
325325
"G": function(cm) { cm.setOption("keyMap", "vim-prefix-g");},
326326
"Shift-D": function(cm) {
327-
// commented out verions works, but I left original, cause maybe
328-
// I don't know vim enouth to see what it does
329-
/* var cur = cm.getCursor();
330-
var f = {line: cur.line, ch: cur.ch}, t = {line: cur.line};
331-
pushInBuffer(cm.getRange(f, t));
332-
*/
327+
var cursor = cm.getCursor();
328+
var lineN = cursor.line;
329+
var line = cm.getLine(lineN);
330+
cm.setLine(lineN, line.slice(0, cursor.ch));
331+
333332
emptyBuffer();
334-
mark["Shift-D"] = cm.getCursor(false).line;
335-
cm.setCursor(cm.getCursor(true).line);
336-
delTillMark(cm,"Shift-D"); mark = [];
333+
pushInBuffer(line.slice(cursor.ch));
334+
335+
if (repeatCount > 1) {
336+
// we've already done it once
337+
--repeatCount;
338+
// the lines dissapear (ie, cursor stays on the same lineN),
339+
// so only incremenet once
340+
++lineN;
341+
342+
iterTimes(function(i) {
343+
pushInBuffer(cm.getLine(lineN));
344+
cm.removeLine(lineN);
345+
});
346+
}
337347
},
338348

339349
"S": function (cm) {

0 commit comments

Comments
 (0)