diff --git a/autotests/src/vimode/emulatedcommandbar.cpp b/autotests/src/vimode/emulatedcommandbar.cpp --- a/autotests/src/vimode/emulatedcommandbar.cpp +++ b/autotests/src/vimode/emulatedcommandbar.cpp @@ -1947,7 +1947,7 @@ // Test that 0 is accepted as a line index (and treated as 1) in a range specifier DoTest("bar\nbar\nbar", ":0,$s/bar/foo/g\\enter", "foo\nfoo\nfoo"); DoTest("bar\nbar\nbar", ":1,$s/bar/foo/g\\enter", "foo\nfoo\nfoo"); - DoTest("bar\nbar\nbar", ":0,2$s/bar/foo/g\\enter", "foo\nfoo\nbar"); + DoTest("bar\nbar\nbar", ":0,2s/bar/foo/g\\enter", "foo\nfoo\nbar"); // On ctrl-d, delete the "search" term in a s/search/replace/xx BeginTest("foo bar"); diff --git a/src/vimode/commandrangeexpressionparser.cpp b/src/vimode/commandrangeexpressionparser.cpp --- a/src/vimode/commandrangeexpressionparser.cpp +++ b/src/vimode/commandrangeexpressionparser.cpp @@ -115,6 +115,11 @@ commandTmp.remove(RE_CmdRange()); + // Vi indexes lines starting from 1; however, it does accept 0 as a valid line index + // and treats it as 1 + position1 = (position1 == 0) ? 1 : position1; + position2 = (position2 == 0) ? 1 : position2; + // special case: if the command is just a number with an optional +/- prefix, rewrite to "goto" if (commandTmp.isEmpty()) { destTransformedCommand = QStringLiteral("goto %1").arg(position1);