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

from yesterday to y(e(s(t(e(r(d(a(y)#)#)#)#)#)#)#)#

Expand Messages
  • marc chantreux
    Hi all, I m trying to start from this line : yesterday to go to this one : y(e(s(t(e(r(d(a(y)#)#)#)#)#)#)#)# ... it s a first step : yesterday - y(esterday)#
    Message 1 of 7 , Mar 2, 2006
    • 0 Attachment
      Hi all,


      I'm trying to start from this line :

      yesterday

      to go to this one :

      y(e(s(t(e(r(d(a(y)#)#)#)#)#)#)#)#

      i wrote it :

      :s/\v[^(]\zs([a-z])(.*)/(\1\2)#/

      it's a first step :

      yesterday -> y(esterday)#

      now i would like to add steps and trying something like :

      :while s/\v[^(]\zs([a-z])(.*)/(\1\2)#/ | end

      this doesn't work, any idea ?

      also, i'm dreaming about the perl's x modifier to keep my RE human
      readble. We can write something like that :

      while s/\v
      " \1 is a letter that not follows a (
      [^(]\zs([a-z])
      " \2 is the rest of the string
      (.*)
      /
      (\1\2)#
      / | end


      I haven't see something like that in the doc and wonder if it's planned.

      regards
      mc
    • Yakov Lerner
      ... s/// is not expression, and it does not return a value that while could check. So s/// is not usable as a condition of while . s/// is usable as a body
      Message 2 of 7 , Mar 2, 2006
      • 0 Attachment
        "marc chantreux" <marc.chantreux@...> wrote:
        > I'm trying to start from this line :
        >
        > yesterday
        >
        > to go to this one :
        >
        > y(e(s(t(e(r(d(a(y)#)#)#)#)#)#)#)#
        >
        > i wrote it :
        >
        > :s/\v[^(]\zs([a-z])(.*)/(\1\2)#/
        >
        > it's a first step :
        >
        > yesterday -> y(esterday)#
        >
        > now i would like to add steps and trying something like :
        >
        > :while s/\v[^(]\zs([a-z])(.*)/(\1\2)#/ | end

        s/// is not expression, and it does not return a value that 'while'
        could check.
        So s/// is not usable as a condition of 'while'. s/// is usable as a
        body of
        'while', though. You need

        :while getline('.')=~"something" | s/\v[^(]\zs([a-z])(.*)/(\1\2)#/ |
        endw

        where "something" is patterns that you need to figure out,
        possibly "[a-z][a-z]"

        Yakov
        --

        iler_ml@...

        --
        http://www.fastmail.fm - The professional email service
      • Gerald Lai
        ... I believe you (Yakov) came up with an elegant way of doing repeated search and replace. You modified Tim Chase s expression in a post a short while back. I
        Message 3 of 7 , Mar 2, 2006
        • 0 Attachment
          On Thu, 2 Mar 2006, Yakov Lerner wrote:

          > "marc chantreux" <marc.chantreux@...> wrote:
          >> I'm trying to start from this line :
          >>
          >> yesterday
          >>
          >> to go to this one :
          >>
          >> y(e(s(t(e(r(d(a(y)#)#)#)#)#)#)#)#
          >>
          >> i wrote it :
          >>
          >> :s/\v[^(]\zs([a-z])(.*)/(\1\2)#/
          >>
          >> it's a first step :
          >>
          >> yesterday -> y(esterday)#
          >>
          >> now i would like to add steps and trying something like :
          >>
          >> :while s/\v[^(]\zs([a-z])(.*)/(\1\2)#/ | end
          >
          > s/// is not expression, and it does not return a value that 'while'
          > could check.
          > So s/// is not usable as a condition of 'while'. s/// is usable as a
          > body of
          > 'while', though. You need
          >
          > :while getline('.')=~"something" | s/\v[^(]\zs([a-z])(.*)/(\1\2)#/ |
          > endw
          >
          > where "something" is patterns that you need to figure out,
          > possibly "[a-z][a-z]"

          I believe you (Yakov) came up with an elegant way of doing repeated
          search and replace. You modified Tim Chase's expression in a post a
          short while back. I knew it was one of those gems that I had to note
          down ;)

          The general expression for a repeated search & replace is:

          :g/<search>/wh getline(".")=~@/|s//<replace>/|endw

          Marc, you were right on target. Simply put in your <search> & <replace>
          into the command above. This should do what you want:

          :g/\v[^(]\zs([a-z])(.*)/wh getline(".")=~@/|s//(\1\2)#/|endw

          Hope this helps.
          --
          Gerald
        • John Love-Jensen
          Hi everyone, ... That s cool. And was the response to one of my earlier inquiries. :-) How can I bind this to, say, , where the and the
          Message 4 of 7 , Mar 2, 2006
          • 0 Attachment
            Hi everyone,

            Begging for a Missouri example (the Show Me state):

            > The general expression for a repeated search & replace is:
            >
            > :g/<search>/wh getline(".")=~@/|s//<replace>/|endw

            That's cool. And was the response to one of my earlier inquiries. :-)

            How can I bind this to, say, <F10>, where the <search> and the <replace> are
            prompted for?

            Even though I've been using Vim since 5.0, I've only written the simplest of
            macro key bindings for my ~/.vimrc file.

            By-and-large, Vim does everything I need/want right out of the box. :-)

            Thanks Bram! (And thanks Bill Joy, for vi!)

            Sincerely,
            --Eljay
          • Yakov Lerner
            ... g/ .s. /wh getline( . )=~@/|s// .r. |endw (untested) Yakov -- iler_ml@fastmail.fm -- http://www.fastmail.fm - A fast, anti-spam email service.
            Message 5 of 7 , Mar 2, 2006
            • 0 Attachment
              "John Love-Jensen" <eljay@...> wrote:
              > > The general expression for a repeated search & replace is:
              > >
              > > :g/<search>/wh getline(".")=~@/|s//<replace>/|endw
              > How can I bind this to, say, <F10>, where the <search> and the <replace>
              > are
              > prompted for?

              :map <f10> :let s=input("Search:")|let r=input("Replace:")|exe
              'g/'.s.'/wh getline(".")=~@/|s//'.r.'|endw'

              (untested)

              Yakov
              --

              iler_ml@...

              --
              http://www.fastmail.fm - A fast, anti-spam email service.
            • marc chantreux
              Hi ... i ve noticed this kind of answer but didn t realized it can work in a ... to act only with the current line Thank you all for help. mc
              Message 6 of 7 , Mar 2, 2006
              • 0 Attachment
                Hi

                > :g/\v[^(]\zs([a-z])(.*)/wh getline(".")=~@/|s//(\1\2)#/|endw

                i've noticed this kind of answer but didn't realized it can work in a
                range. so my final line is :

                :.g/\v[^(]\zs([a-z])(.*)/wh getline(".")=~@/|s//(\1\2)#/|endw

                to act only with the current line


                Thank you all for help.


                mc
              • Benji Fisher
                ... Also untested, but I think that ... should work just as well. No, better use instead of | . The marks are OK, though. ... HTH --Benji Fisher
                Message 7 of 7 , Mar 2, 2006
                • 0 Attachment
                  On Thu, Mar 02, 2006 at 04:17:05PM +0200, Yakov Lerner wrote:
                  > "John Love-Jensen" <eljay@...> wrote:
                  > > > The general expression for a repeated search & replace is:
                  > > >
                  > > > :g/<search>/wh getline(".")=~@/|s//<replace>/|endw
                  > > How can I bind this to, say, <F10>, where the <search> and the <replace>
                  > > are
                  > > prompted for?
                  >
                  > :map <f10> :let s=input("Search:")|let r=input("Replace:")|exe
                  > 'g/'.s.'/wh getline(".")=~@/|s//'.r.'|endw'
                  >
                  > (untested)

                  Also untested, but I think that

                  :map <f10> exe 'g/'.input("Search:").'/wh getline(".")=~@/|s//'.input("Replace:").'|endw'

                  should work just as well. No, better use <bar> instead of | . The "
                  marks are OK, though.

                  :help map-comments

                  HTH --Benji Fisher
                Your message has been successfully submitted and would be delivered to recipients shortly.