Skip to content

Commit 8dd9a87

Browse files
Travis Heppemarijnh
authored andcommitted
[vim bindings] Rewrite queries that end in $
into a form that CodeMirror can understand.
1 parent ee3a8f7 commit 8dd9a87

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

keymap/vim.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,6 +4509,10 @@
45094509
if (tokens.length) {
45104510
regexPart = tokens[0];
45114511
replacePart = tokens[1];
4512+
if (regexPart && regexPart[regexPart.length - 1] === '$') {
4513+
regexPart = regexPart.slice(0, regexPart.length - 1) + '\\n';
4514+
replacePart = replacePart ? replacePart + '\n' : '\n';
4515+
}
45124516
if (replacePart !== undefined) {
45134517
if (getOption('pcre')) {
45144518
replacePart = unescapeRegexReplace(replacePart);

test/vim_test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3789,6 +3789,14 @@ testSubstitute('ex_substitute_multibackslash_replacement', {
37893789
value: 'one,two \n three,four',
37903790
expectedValue: 'one\\\\\\\\two \n three\\\\\\\\four', // 2*8 backslashes.
37913791
expr: '%s/,/\\\\\\\\\\\\\\\\/g'}); // 16 backslashes.
3792+
testSubstitute('ex_substitute_dollar_match', {
3793+
value: 'one,two \n three,four',
3794+
expectedValue: 'one,two ,\n three,four',
3795+
expr: '%s/$/,/g'});
3796+
testSubstitute('ex_substitute_newline_match', {
3797+
value: 'one,two \n three,four',
3798+
expectedValue: 'one,two , three,four',
3799+
expr: '%s/\\n/,/g'});
37923800
testSubstitute('ex_substitute_newline_replacement', {
37933801
value: 'one,two \n three,four',
37943802
expectedValue: 'one\ntwo \n three\nfour',

0 commit comments

Comments
 (0)