Skip to content

Commit 795f137

Browse files
benhormannmarijnh
authored andcommitted
[vim] add :vglobal ex command
1 parent 6523439 commit 795f137

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

keymap/vim.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
{ name: 'yank', shortName: 'y' },
245245
{ name: 'delmarks', shortName: 'delm' },
246246
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true },
247+
{ name: 'vglobal', shortName: 'v' },
247248
{ name: 'global', shortName: 'g' }
248249
];
249250

@@ -5018,6 +5019,10 @@
50185019
}
50195020
cm.replaceRange(text.join('\n'), curStart, curEnd);
50205021
},
5022+
vglobal: function(cm, params) {
5023+
// global inspects params.commandName
5024+
this.global(cm, params);
5025+
},
50215026
global: function(cm, params) {
50225027
// a global command is of the form
50235028
// :[range]g/pattern/[cmd]
@@ -5027,6 +5032,7 @@
50275032
showConfirm(cm, 'Regular Expression missing from global');
50285033
return;
50295034
}
5035+
var inverted = params.commandName[0] === 'v';
50305036
// range is specified here
50315037
var lineStart = (params.line !== undefined) ? params.line : cm.firstLine();
50325038
var lineEnd = params.lineEnd || params.line || cm.lastLine();
@@ -5055,7 +5061,7 @@
50555061
for (var i = lineStart; i <= lineEnd; i++) {
50565062
var line = cm.getLineHandle(i);
50575063
var matched = query.test(line.text);
5058-
if (matched) {
5064+
if (matched !== inverted) {
50595065
matchedLines.push(cmd ? line : line.text);
50605066
}
50615067
}

test/vim_test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,15 @@ testVim('ex_global_confirm', function(cm, vim, helpers) {
41134113
onKeyDown({keyCode: KEYCODES.y}, '', close);
41144114
eq('one two\n two two\n one one\n two one\n one one', cm.getValue());
41154115
}, {value: 'one one\n one one\n one one\n one one\n one one'});
4116+
// test for :vglobal command
4117+
testVim('ex_vglobal', function(cm, vim, helpers) {
4118+
helpers.doEx('v/e/s/o/e');
4119+
eq('one\n twe\n three\n feur\n five\n', cm.getValue());
4120+
cm.openNotification = helpers.fakeOpenNotification(function(text) {
4121+
eq('one\n three\n feur\n', text);
4122+
});
4123+
helpers.doEx('v/[vw]');
4124+
}, {value: 'one\n two\n three\n four\n five\n'});
41164125
// Basic substitute tests.
41174126
testVim('ex_substitute_same_line', function(cm, vim, helpers) {
41184127
cm.setCursor(1, 0);

0 commit comments

Comments
 (0)