Skip to content

Commit d733766

Browse files
benhormannmarijnh
authored andcommitted
[vim] fix substitute command when joining multiple lines
1 parent 1770901 commit d733766

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

keymap/vim.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5268,7 +5268,7 @@
52685268
// Set up all the functions.
52695269
cm.state.vim.exMode = true;
52705270
var done = false;
5271-
var lastPos, modifiedLineNumber;
5271+
var lastPos, modifiedLineNumber, joined;
52725272
function replaceAll() {
52735273
cm.operation(function() {
52745274
while (!done) {
@@ -5285,13 +5285,14 @@
52855285
searchCursor.replace(newText);
52865286
modifiedLineNumber = searchCursor.to().line;
52875287
lineEnd += modifiedLineNumber - unmodifiedLineNumber;
5288+
joined = modifiedLineNumber < unmodifiedLineNumber;
52885289
}
52895290
function next() {
52905291
// The below only loops to skip over multiple occurrences on the same
52915292
// line when 'global' is not true.
52925293
while(searchCursor.findNext() &&
52935294
isInRange(searchCursor.from(), lineStart, lineEnd)) {
5294-
if (!global && searchCursor.from().line == modifiedLineNumber) {
5295+
if (!global && searchCursor.from().line == modifiedLineNumber && !joined) {
52955296
continue;
52965297
}
52975298
cm.scrollIntoView(searchCursor.from(), 30);

test/vim_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,10 @@ testSubstitute('ex_substitute_newline_join_global', {
43114311
value: 'one,two \n three,four \n five \n six',
43124312
expectedValue: 'one,two \n three,four , five \n six',
43134313
expr: '2s/\\n/,/g'});
4314+
testSubstitute('ex_substitute_newline_join_noglobal', {
4315+
value: 'one,two \n three,four \n five \n six\n',
4316+
expectedValue: 'one,two \n three,four , five , six\n',
4317+
expr: '2,3s/\\n/,/'});
43144318
testSubstitute('ex_substitute_newline_replacement', {
43154319
value: 'one,two, \n three,four,',
43164320
expectedValue: 'one\ntwo\n \n three\nfour\n',

0 commit comments

Comments
 (0)