Loading ...
Sorry, an error occurred while loading the content.
 

:substitute replacement with %

Expand Messages
  • Ciaran McCreesh
    ... SVR4.0 vi handles this, but vim doesn t. Is this something that s worth supporting? Patch attached. -- Ciaran McCreesh : Gentoo Developer (Vim, Fluxbox,
    Message 1 of 17 , Jan 6, 2005
      According to POSIX, for the ex :substitute command:

      > If the entire replacement pattern is '%', the last replacement pattern
      > to an s command shall be used.

      SVR4.0 vi handles this, but vim doesn't. Is this something that's worth
      supporting? Patch attached.

      --
      Ciaran McCreesh : Gentoo Developer (Vim, Fluxbox, shell tools)
      Mail : ciaranm at gentoo.org
      Web : http://dev.gentoo.org/~ciaranm
    • Bram Moolenaar
      ... The Vi I have takes the % in :s/pat/%/ literally. Since it s not uncommon to replace something with a literal % , we can t simply change it. The ex
      Message 2 of 17 , Jan 6, 2005
        Ciaran McCreesh wrote:

        > According to POSIX, for the ex :substitute command:
        >
        > > If the entire replacement pattern is '%', the last replacement pattern
        > > to an s command shall be used.
        >
        > SVR4.0 vi handles this, but vim doesn't. Is this something that's worth
        > supporting? Patch attached.

        The Vi I have takes the '%' in ":s/pat/%/" literally. Since it's not
        uncommon to replace something with a literal '%', we can't simply change
        it.

        The ex part of the POSIX standard wasn't written very well. It's a nice
        guideline, but certainly not a definitive standard. The old Vi versions
        are a better standard (so long as something doesn't look like a bug).

        So, what old versions of Vi handle the '%' in a special way?

        --
        hundred-and-one symptoms of being an internet addict:
        252. You vote for foreign officials.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
      • Antony Scriven
        ... The old BSD vi on sourceforge and HPUX vi don t handle % in a special way. (FWIW neither does viper-mode!) Nvi follows POSIX and does treat % specially. I
        Message 3 of 17 , Jan 6, 2005
          On Jan 06, Bram Moolenaar wrote:

          > Ciaran McCreesh wrote:
          >
          > > According to POSIX, for the ex :substitute command:
          > >
          > > > If the entire replacement pattern is '%', the last
          > > > replacement pattern to an s command shall be used.
          > >
          > > SVR4.0 vi handles this, but vim doesn't. Is this
          > > something that's worth supporting? Patch attached.
          >
          > The Vi I have takes the '%' in ":s/pat/%/" literally.
          > Since it's not uncommon to replace something with a
          > literal '%', we can't simply change
          > it.
          >
          > The ex part of the POSIX standard wasn't written very
          > well. It's a nice guideline, but certainly not a
          > definitive standard. The old Vi versions are a better
          > standard (so long as something doesn't look like a bug).
          >
          > So, what old versions of Vi handle the '%' in a special
          > way?

          The old BSD vi on sourceforge and HPUX vi don't handle % in
          a special way. (FWIW neither does viper-mode!) Nvi follows
          POSIX and does treat % specially.

          I guess the reason for POSIX specifying this is that it is
          compatible with ed (which doesn't treat ~ specially in the
          replacement text).

          Antony
        • Ciaran McCreesh
          On Thu, 06 Jan 2005 12:40:54 +0100 Bram Moolenaar ... * nvi (I have 1.81.5) handles % specially * SVR4 vi (Solaris 7 and IRIX 6) handles %
          Message 4 of 17 , Jan 6, 2005
            On Thu, 06 Jan 2005 12:40:54 +0100 Bram Moolenaar <Bram@...>
            wrote:
            | So, what old versions of Vi handle the '%' in a special way?

            * nvi (I have 1.81.5) handles % specially

            * SVR4 vi (Solaris 7 and IRIX 6) handles % specially

            * ex-vi (I have 041202) handles % specially. From the changelog it looks
            like this is a fairly recent addition -- I'm guessing Antony is using an
            older release?

            * elvis (I have 2.2.0) doesn't handle % specially

            My usual source of older UNIX systems is unavailable, so I can't check
            at what point SunOS/Solaris started supporting %.

            --
            Ciaran McCreesh : Gentoo Developer (Vim, Fluxbox, shell tools)
            Mail : ciaranm at gentoo.org
            Web : http://dev.gentoo.org/~ciaranm
          • Antony Scriven
            ... Yes it looks like you are right: I have version 1/3/04 (confusing date format, that). This change implies that the original vi didn t treat % specially.
            Message 5 of 17 , Jan 6, 2005
              On Jan 06, Ciaran McCreesh wrote:

              > On Thu, 06 Jan 2005 12:40:54 +0100 Bram Moolenaar
              > <Bram@...> wrote:
              > | So, what old versions of Vi handle the '%' in a special
              > | way?
              >
              > [...]
              >
              > * ex-vi (I have 041202) handles % specially. From the
              > changelog it looks like this is a fairly recent addition
              > -- I'm guessing Antony is using an older release?
              >
              > [...]

              Yes it looks like you are right: I have version 1/3/04
              (confusing date format, that). This change implies that the
              original vi didn't treat % specially. Though I'm now
              beginning to wonder what other changes might have been made.

              Antony
            • Bram Moolenaar
              ... I think you refer to the vi that was produced from the original vi code, after the source code was released to the public. They have made additions of
              Message 6 of 17 , Jan 6, 2005
                Antony Scriven wrote:

                > > * ex-vi (I have 041202) handles % specially. From the
                > > changelog it looks like this is a fairly recent addition
                > > -- I'm guessing Antony is using an older release?
                > >
                > > [...]
                >
                > Yes it looks like you are right: I have version 1/3/04
                > (confusing date format, that). This change implies that the
                > original vi didn't treat % specially. Though I'm now
                > beginning to wonder what other changes might have been made.

                I think you refer to the vi that was produced from the original vi code,
                after the source code was released to the public. They have made
                additions of their own, thus you can't be sure whether something was in
                the original. Their home page is http://ex-vi.sourceforge.net/.

                I have the BSD 4.2 version source code, only modified to make it compile
                and run (still crashes sometimes). It doesn't handle the '%'
                differently. It looks like a System V addition. Really bad choice to
                use a printable character instead of backslash-something...

                The code can be found here:
                http://www.pell.portland.or.us/~orc/vi.4.2bsd.tar.gz

                --
                hundred-and-one symptoms of being an internet addict:
                253. You wait for a slow loading web page before going to the toilet.

                /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
              • Nikolai Weibull
                ... Kind of like & ;-), nikolai -- ... main(){printf(&linux[ 021%six 012 0 ],(linux)[ have ]+ fun -97);}
                Message 7 of 17 , Jan 6, 2005
                  * Bram Moolenaar <Bram@...> [Jan 06, 2005 14:40]:
                  > I have the BSD 4.2 version source code, only modified to make it
                  > compile and run (still crashes sometimes). It doesn't handle the '%'
                  > differently. It looks like a System V addition. Really bad choice to
                  > use a printable character instead of backslash-something...

                  Kind of like '&' ;-),
                  nikolai

                  --
                  ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
                  ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
                  ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
                  main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
                • Antony Scriven
                  ... Ah, thanks for that! I guess I should have searched a little harder. I thought ex-vi project would be suitable as a reference copy but I guess it is
                  Message 8 of 17 , Jan 6, 2005
                    On Jan 06, Bram Moolenaar wrote:

                    > Antony Scriven wrote:
                    >
                    > > > * ex-vi (I have 041202) handles % specially. From the
                    > > > changelog it looks like this is a fairly recent addition
                    > > > -- I'm guessing Antony is using an older release?
                    > > >
                    > > > [...]
                    > >
                    > > Yes it looks like you are right: I have version 1/3/04
                    > > (confusing date format, that). This change implies that the
                    > > original vi didn't treat % specially. Though I'm now
                    > > beginning to wonder what other changes might have been made.
                    >
                    > I think you refer to the vi that was produced from the
                    > original vi code, after the source code was released to
                    > the public. They have made additions of their own, thus
                    > you can't be sure whether something was in the original.
                    > Their home page is http://ex-vi.sourceforge.net/.
                    >
                    > I have the BSD 4.2 version source code, only modified to
                    > make it compile and run (still crashes sometimes). It
                    > doesn't handle the '%' differently. It looks like a
                    > System V addition. Really bad choice to use a printable
                    > character instead of backslash-something...
                    >
                    > The code can be found here:
                    > http://www.pell.portland.or.us/~orc/vi.4.2bsd.tar.gz

                    Ah, thanks for that! I guess I should have searched a little
                    harder. I thought ex-vi project would be suitable as a
                    reference copy but I guess it is starting to change too
                    much.

                    Out of interest I've just found a copy of the 3bsd
                    distribution and compiled the vi on that:

                    Version 3.2, January 4, 1980

                    That doesn't treat % specially either, so I guess vi changed
                    from being like ed in this regard some time earlier.

                    Antony
                  • Bram Moolenaar
                    ... And ~ . Never liked the special meaning of ~ and & , even I make a mistake with that sometimes. But this is what Vi does, thus we need to keep this
                    Message 9 of 17 , Jan 6, 2005
                      Nikolai Weibull wrote:

                      > * Bram Moolenaar <Bram@...> [Jan 06, 2005 14:40]:
                      > > I have the BSD 4.2 version source code, only modified to make it
                      > > compile and run (still crashes sometimes). It doesn't handle the '%'
                      > > differently. It looks like a System V addition. Really bad choice to
                      > > use a printable character instead of backslash-something...
                      >
                      > Kind of like '&' ;-),

                      And '~'. Never liked the special meaning of '~' and '&', even I make a
                      mistake with that sometimes. But this is what Vi does, thus we need to
                      keep this behavior.

                      --
                      If VIM were a woman, I'd marry her. Slim, organized, helpful
                      and beautiful; what's not to like? --David A. Rogers

                      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                      /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                      \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                      \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
                    • Bram Moolenaar
                      ... As far as I know, vi and ex were not based on ed. Some (many?) features of ed have been included to make ed users feel at home. -- hundred-and-one
                      Message 10 of 17 , Jan 6, 2005
                        Antony Scriven wrote:

                        > Out of interest I've just found a copy of the 3bsd
                        > distribution and compiled the vi on that:
                        >
                        > Version 3.2, January 4, 1980
                        >
                        > That doesn't treat % specially either, so I guess vi changed
                        > from being like ed in this regard some time earlier.

                        As far as I know, vi and ex were not based on ed. Some (many?) features
                        of ed have been included to make ed users feel at home.

                        --
                        hundred-and-one symptoms of being an internet addict:
                        254. You wake up daily with your keyboard printed on your forehead.

                        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                        /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                        \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
                      • Nikolai Weibull
                        ... Me more than sometimes... ... Yeah, thank god for the concept of backwards compatability, nikolai -- ...
                        Message 11 of 17 , Jan 6, 2005
                          * Bram Moolenaar <Bram@...> [Jan 06, 2005 17:00]:
                          > > > I have the BSD 4.2 version source code, only modified to make it
                          > > > compile and run (still crashes sometimes). It doesn't handle the
                          > > > '%' differently. It looks like a System V addition. Really bad
                          > > > choice to use a printable character instead of
                          > > > backslash-something...

                          > > Kind of like '&' ;-),

                          > And '~'. Never liked the special meaning of '~' and '&', even I make
                          > a mistake with that sometimes.

                          Me more than sometimes...

                          > But this is what Vi does, thus we need to keep this behavior.

                          Yeah, thank god for the concept of backwards compatability,
                          nikolai

                          --
                          ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
                          ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
                          ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
                          main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
                        • Antony Scriven
                          ... Hmm. You may be right. From http://www.dcs.qmul.ac.uk/~george/history/ `I explained that em was an extension of ed [...] I interpreted this to mean
                          Message 12 of 17 , Jan 6, 2005
                            On Jan 06, Bram Moolenaar wrote:

                            > Antony Scriven wrote:
                            >
                            > > Out of interest I've just found a copy of the 3bsd
                            > > distribution and compiled the vi on that:
                            > >
                            > > Version 3.2, January 4, 1980
                            > >
                            > > That doesn't treat % specially either, so I guess vi changed
                            > > from being like ed in this regard some time earlier.
                            >
                            > As far as I know, vi and ex were not based on ed. Some
                            > (many?) features of ed have been included to make ed
                            > users feel at home.

                            Hmm. You may be right.

                            From http://www.dcs.qmul.ac.uk/~george/history/

                            `I explained that 'em' was an extension of 'ed' [...]'

                            I interpreted this to mean that em was based on ed's code,
                            but I guess `extension' doesn't necessarily mean that.

                            Antony
                          • Ciaran McCreesh
                            On Thu, 6 Jan 2005 11:16:04 +0000 Ciaran McCreesh ... Attached is an updated patch which only enables this feature if / is included in
                            Message 13 of 17 , Feb 12, 2005
                              On Thu, 6 Jan 2005 11:16:04 +0000 Ciaran McCreesh <ciaranm@...>
                              wrote:
                              | According to POSIX, for the ex :substitute command:
                              |
                              | > If the entire replacement pattern is '%', the last replacement
                              | > pattern to an s command shall be used.
                              |
                              | SVR4.0 vi handles this, but vim doesn't. Is this something that's
                              | worth supporting? Patch attached.

                              Attached is an updated patch which only enables this feature if '/' is
                              included in cpoptions ('%' is already taken, unfortunately). When
                              VIM_POSIX is set, this option is enabled.

                              --
                              Ciaran McCreesh : Gentoo Developer (Vim, Fluxbox, shell tools)
                              Mail : ciaranm at gentoo.org
                              Web : http://dev.gentoo.org/~ciaranm
                            • Bram Moolenaar
                              ... Where in the POSIX standard do you find this? In my version, on page 391 it says: -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                              Message 14 of 17 , Feb 13, 2005
                                Ciaran McCreesh wrote:

                                > On Thu, 6 Jan 2005 11:16:04 +0000 Ciaran McCreesh <ciaranm@...>
                                > wrote:
                                > | According to POSIX, for the ex :substitute command:
                                > |
                                > | > If the entire replacement pattern is '%', the last replacement
                                > | > pattern to an s command shall be used.
                                > |
                                > | SVR4.0 vi handles this, but vim doesn't. Is this something that's
                                > | worth supporting? Patch attached.
                                >
                                > Attached is an updated patch which only enables this feature if '/' is
                                > included in cpoptions ('%' is already taken, unfortunately). When
                                > VIM_POSIX is set, this option is enabled.

                                Where in the POSIX standard do you find this? In my version, on page
                                391 it says:

                                -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                Replacement Strings in ex

                                The character '&' ('\&' if the editor option magic is not set) in the
                                replacement string shall stand for the text matched by the pattern to be
                                replaced. The character '~' ('\~' if magic is not set) shall be replaced
                                by the replacement part of the previous substitute command. The sequence
                                \n , where n is an integer, shall be replaced by the text matched by the
                                pattern enclosed in the nth set of parentheses \( and \) .

                                The strings '\l', '\u', '\L', and '\U' can be used to modify the case of
                                elements in the replacement string (using the '\&' or "\"digit)
                                notation. The string '\l' ('\u') shall cause the character that follows
                                to be converted to lowercase (uppercase). The string '\L' ('\U') shall
                                cause all characters subsequent to it to be converted to lowercase
                                (uppercase) as they are inserted by the substitution until the string
                                '\e' or '\E', or the end of the replacement string, is encountered.

                                Otherwise, any character following a backslash shall be treated as that
                                literal character, and the escaping backslash shall be discarded.
                                -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

                                It doesn't mention % at all.

                                --
                                From "know your smileys":
                                :'-D Laughing so much that they're crying

                                /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                                \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
                              • Ciaran McCreesh
                                On Sun, 13 Feb 2005 18:50:29 +0100 Bram Moolenaar ... It s under the ex - Extended Description - Substitute section, not under
                                Message 15 of 17 , Feb 13, 2005
                                  On Sun, 13 Feb 2005 18:50:29 +0100 Bram Moolenaar <Bram@...>
                                  wrote:
                                  | Ciaran McCreesh wrote:
                                  | > On Thu, 6 Jan 2005 11:16:04 +0000 Ciaran McCreesh
                                  | > <ciaranm@...> wrote:
                                  | > | According to POSIX, for the ex :substitute command:
                                  | > |
                                  | > | > If the entire replacement pattern is '%', the last replacement
                                  | > | > pattern to an s command shall be used.
                                  | > |
                                  | > | SVR4.0 vi handles this, but vim doesn't. Is this something that's
                                  | > | worth supporting? Patch attached.
                                  | >
                                  | > Attached is an updated patch which only enables this feature if '/'
                                  | > is included in cpoptions ('%' is already taken, unfortunately). When
                                  | > VIM_POSIX is set, this option is enabled.
                                  |
                                  | Where in the POSIX standard do you find this? In my version, on page
                                  | 391 it says:
                                  |
                                  | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                  | =- Replacement Strings in ex

                                  It's under the "ex - Extended Description - Substitute" section, not
                                  under "Replacement Strings in ex". The second paragraph following the
                                  synopsis for substitute is:

                                  > The trailing delimiter can be omitted from pattern or from repl at the
                                  > end of the command line. If both pattern and repl are not specified or
                                  > are empty (for example, "//" ), the last s command shall be repeated.
                                  > If only pattern is not specified or is empty, the last regular
                                  > expression used in the editor shall be used as the pattern. If only
                                  > repl is not specified or is empty, the pattern shall be replaced by
                                  > nothing. If the entire replacement pattern is '%', the last
                                  > replacement pattern to an s command shall be used.

                                  The version I'm looking at is the 2004 edition.

                                  --
                                  Ciaran McCreesh : Gentoo Developer (Vim, Fluxbox, shell tools)
                                  Mail : ciaranm at gentoo.org
                                  Web : http://dev.gentoo.org/~ciaranm
                                • Bram Moolenaar
                                  ... OK, I see it now. I tried this in an old Vi version, and it uses the % literally. Thus it s indeed a POSIX thing (perhaps something added in System V).
                                  Message 16 of 17 , Feb 13, 2005
                                    Ciaran McCreesh wrote:

                                    > | Where in the POSIX standard do you find this? In my version, on page
                                    > | 391 it says:
                                    >
                                    > It's under the "ex - Extended Description - Substitute" section, not
                                    > under "Replacement Strings in ex". The second paragraph following the
                                    > synopsis for substitute is:

                                    OK, I see it now.

                                    I tried this in an old Vi version, and it uses the '%' literally. Thus
                                    it's indeed a POSIX thing (perhaps something added in System V).

                                    I'll include the patch now. You may have noticed I'm working on POSIX
                                    compatibility. I obtained a copy of the test suite for this.

                                    --
                                    There's no place like $(HOME)!

                                    /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                    /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                                    \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                    \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
                                  • Keith Roberts
                                    ... Just for my edification: isn t this what we are using ~ for now? -Keith
                                    Message 17 of 17 , Feb 14, 2005
                                      >-----Original Message-----
                                      >From: Ciaran McCreesh [mailto:ciaranm@...]
                                      >Sent: Sunday, February 13, 2005 10:13 AM
                                      >To: Bram Moolenaar
                                      >Cc: vim-dev@...
                                      >Subject: Re: :substitute replacement with %
                                      >
                                      >On Sun, 13 Feb 2005 18:50:29 +0100 Bram Moolenaar <Bram@...>
                                      >wrote:
                                      >| Ciaran McCreesh wrote:
                                      >| > On Thu, 6 Jan 2005 11:16:04 +0000 Ciaran McCreesh
                                      >| > <ciaranm@...> wrote:
                                      >| > | According to POSIX, for the ex :substitute command:
                                      >| > |
                                      >| > | > If the entire replacement pattern is '%', the last replacement
                                      >| > | > pattern to an s command shall be used.
                                      >| > |
                                      >| > | SVR4.0 vi handles this, but vim doesn't. Is this
                                      >something that's
                                      >| > | worth supporting? Patch attached.
                                      >| >
                                      >| > Attached is an updated patch which only enables this feature if '/'
                                      >| > is included in cpoptions ('%' is already taken,
                                      >unfortunately). When
                                      >| > VIM_POSIX is set, this option is enabled.
                                      >|
                                      >| Where in the POSIX standard do you find this? In my version, on page
                                      >| 391 it says:
                                      >|
                                      >| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                      >| =- Replacement Strings in ex
                                      >
                                      >It's under the "ex - Extended Description - Substitute"
                                      >section, not under "Replacement Strings in ex". The second
                                      >paragraph following the synopsis for substitute is:
                                      >
                                      >> The trailing delimiter can be omitted from pattern or from
                                      >repl at the
                                      >> end of the command line. If both pattern and repl are not
                                      >specified or
                                      >> are empty (for example, "//" ), the last s command shall be repeated.
                                      >> If only pattern is not specified or is empty, the last regular
                                      >> expression used in the editor shall be used as the pattern. If only
                                      >> repl is not specified or is empty, the pattern shall be replaced by
                                      >> nothing. If the entire replacement pattern is '%', the last
                                      >> replacement pattern to an s command shall be used.
                                      >
                                      >The version I'm looking at is the 2004 edition.

                                      Just for my edification: isn't this what we are using '~' for now?

                                      -Keith
                                    Your message has been successfully submitted and would be delivered to recipients shortly.