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 @@ -1943,6 +1943,12 @@ DoTest("foo\nbar\nxyz", ":%delete\\enter", ""); DoTest("foo\nbar\nxyz\nbaz", "jVj:delete\\enter", "foo\nbaz"); DoTest("foo\nbar\nxyz\nbaz", "j2:delete\\enter", "foo\nbaz"); + + // 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"); + // On ctrl-d, delete the "search" term in a s/search/replace/xx BeginTest("foo bar"); TestPressKey(":s/x\\\\\\\\\\\\/yz/rep\\\\\\\\\\\\/lace/g\\ctrl-d"); 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);