Skip to content

Commit 8facd90

Browse files
benhormannmarijnh
authored andcommitted
[vim] Allow Ex-Commands with non-word names
1 parent 25e7a32 commit 8facd90

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

keymap/vim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4456,7 +4456,7 @@
44564456
}
44574457

44584458
// Parse command name.
4459-
var commandMatch = inputStream.match(/^(\w+)/);
4459+
var commandMatch = inputStream.match(/^(\w+|!!|@@|[!#&*<=>@~])/);
44604460
if (commandMatch) {
44614461
result.commandName = commandMatch[1];
44624462
} else {

test/vim_test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,6 +4479,37 @@ testVim('ex_api_test', function(cm, vim, helpers) {
44794479
is(res,'Mapping to key failed');
44804480
CodeMirror.Vim.mapclear();
44814481
});
4482+
// Testing ex-commands with non-alpha names.
4483+
testVim('ex_special_names', function(cm, vim, helpers) {
4484+
var ran,val;
4485+
var cmds = ['!','!!','#','&','*','<','=','>','@','@@','~','regtest1','RT2'];
4486+
cmds.forEach(function(name){
4487+
CodeMirror.Vim.defineEx(name,'',function(cm,params){
4488+
ran=params.commandName;
4489+
val=params.argString;
4490+
});
4491+
helpers.doEx(':'+name);
4492+
eq(ran,name,'Running ex-command failed');
4493+
helpers.doEx(':'+name+' x');
4494+
eq(val,' x','Running ex-command with param failed: '+name);
4495+
if(/^\W+$/.test(name)){
4496+
helpers.doEx(':'+name+'y');
4497+
eq(val,'y','Running ex-command with param failed: '+name);
4498+
}
4499+
else{
4500+
helpers.doEx(':'+name+'-y');
4501+
eq(val,'-y','Running ex-command with param failed: '+name);
4502+
}
4503+
if(name!=='!'){
4504+
helpers.doEx(':'+name+'!');
4505+
eq(ran,name,'Running ex-command with bang failed');
4506+
eq(val,'!','Running ex-command with bang failed: '+name);
4507+
helpers.doEx(':'+name+'!z');
4508+
eq(ran,name,'Running ex-command with bang & param failed');
4509+
eq(val,'!z','Running ex-command with bang & param failed: '+name);
4510+
}
4511+
});
4512+
});
44824513
// For now, this test needs to be last because it messes up : for future tests.
44834514
testVim('ex_map_key2key_from_colon', function(cm, vim, helpers) {
44844515
helpers.doEx('map : x');

0 commit comments

Comments
 (0)