Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jul 2023 14:36:51 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 272487] vi/nvi: :t wrongly adjusts current-line in the context of a :g command
Message-ID:  <bug-272487-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D272487

            Bug ID: 272487
           Summary: vi/nvi: :t wrongly adjusts current-line in the context
                    of a :g command
           Product: Base System
           Version: Unspecified
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: freebsd@tim.thechases.com

With the following file:

    $ cat <<EOF > test.txt

    blank line above
    pattern line one
    pattern line two
    EOF

The aim was to copy that first blank line before each of the /pattern/
lines.  This works fine in ed(1):

    $ ed test.txt
    52
    g/^pattern/1t-
    ,p

    blank line above

    pattern line one

    pattern line two

However, when I use either of these commands in vi:

    :g/^pattern/1t-
    :g/^pattern/1t.-

it errors with

    Usage: [line [,line]] t line [flags].

Additionally, if I explicitly spell out the relative line count
with either

    :g/^pattern/1t-1
    :g/^pattern/1t.-1

it errors with

    Reference to a line number less than 0

It seems to set the current-line aspect with the absolute line-number
of "1" before processing the relative "-" or ".-" (which should be
relative to the :g/ match)

If I am on one of the /pattern/ lines and issue the same command:

    3G
    :1t-

it works as expected, copying the first/blank line before the current
line.

And strangely, if I do something with the line beforehand (printing
it, showing the line-number with `=3D`, etc), it works too:

    :g/^pattern/.=3D|1t-

Similarly, if I put the blank line at the bottom of the file:

    :1m$
    :g/^pattern/$t-

it also works as expected.  And, FWIW, the original/problematic
command works fine in vim.

Seems to be an `nvi(1)` thing, presenting in both FreeBSD & OpenBSD

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-272487-227>