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

Re: Can I use split() on this?

Expand Messages
  • Tim Chase
    ... The most straightforward would be to do something like %s/ [ ([^]]* )] s* ((.* )/ =join(map(split(submatch(1), ), [ . v:val . ] . submatch(2) ),
    Message 1 of 6 , Mar 12, 2013
      On 2013-03-12 16:23, Cesar Romani wrote:
      > How to convert from
      > [uno\dos\tres](fijo)
      >
      > to
      > [uno](fijo)
      > [dos](fijo)
      > [tres](fijo)

      The most straightforward would be to do something like

      %s/\[\([^]]*\)]\s*\((.*\)/\=join(map(split(submatch(1), '\\'), '"[" .
      v:val . "]" . submatch(2)'), "\n")

      (all on one line). I'm sure there's some way to do something like
      one of the following which got me pretty close:

      %s/\%(\[[^]]*\)\@<=\<\(\w\+\)\>\\\=\([^]]\+]\)\((.*\)/\1]\3\r[\2\3/g

      %s/\%(\[[^]]*\)\@<=\zs\<\(\w\+\)\>\ze\%([^]]*]\((.*\)\)\=/\1]\2\r[/g

      but neither was quite the results I was hoping for.

      -tim


      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • John Little
      ... I take it that uno, dos, tres are arbitrary, and that you might have, say, [uno dos tres cuatro cinco](fijo) I use a repeated substitute for changes like
      Message 2 of 6 , Mar 12, 2013
        On Wednesday, March 13, 2013 10:23:41 AM UTC+13, andalou wrote:
        > How to convert from
        >
        > [uno\dos\tres](fijo)
        >
        > to
        >
        > [uno](fijo)
        > [dos](fijo)
        > [tres](fijo)

        I take it that uno, dos, tres are arbitrary, and that you might have, say,

        [uno\dos\tres\cuatro\cinco](fijo)

        I use a repeated substitute for changes like this. First, I experimented with a search that matches the last item followed by the "fixed" stuff (see, I can use Google, woo hoo):

        /\\[^\\]\+]([^)]\+)

        until I've got it right. Then I put capturing parentheses (in vim that's "\(" and "\)") around the interesting bits and to make sure it still matched:

        /\\\([^\\]\+\)](\([^)]\+\))

        Then, a substitute:

        :s//](\2)\r[\1](\2)

        When that worked, move back to the right line and:

        :while 1 | & | - | endwhile

        Regards, John Little

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Cesar Romani
        Thanks a lot Tim and John, especially the Tim s one-liner. Best Regards, -- Cesar -- -- You received this message from the vim_use maillist. Do not top-post!
        Message 3 of 6 , Mar 12, 2013
          Thanks a lot Tim and John, especially the Tim's one-liner.

          Best Regards,

          --
          Cesar

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Kent
          ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to. For more information,
          Message 4 of 6 , Mar 13, 2013
            another way, without split and join:


            :s/\v([^)]*)(\(.*)/\=substitute(submatch(1),"\\","]".submatch(2)."\n[","g").submatch(2)/

            On Wed, Mar 13, 2013 at 3:53 AM, Cesar Romani <cesar.romani@...> wrote:
            > Thanks a lot Tim and John, especially the Tim's one-liner.
            >
            > Best Regards,
            >
            > --
            > Cesar
            >
            >
            > --
            > --
            > You received this message from the "vim_use" maillist.
            > Do not top-post! Type your reply below the text you are replying to.
            > For more information, visit http://www.vim.org/maillist.php
            >
            > --- You received this message because you are subscribed to the Google
            > Groups "vim_use" group.
            > To unsubscribe from this group and stop receiving emails from it, send an
            > email to vim_use+unsubscribe@....
            > For more options, visit https://groups.google.com/groups/opt_out.
            >
            >

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Cesar Romani
            ... That s brilliant! Thanks. Best Regards, -- Cesar Romani -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below
            Message 5 of 6 , Mar 13, 2013
              On 13/03/2013 06:17 a.m., Kent wrote:
              > another way, without split and join:
              >
              >
              :s/\v([^)]*)(\(.*)/\=substitute(submatch(1),"\\","]".submatch(2)."\n[","g").submatch(2)/

              That's brilliant! Thanks.

              Best Regards,

              --
              Cesar Romani

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            Your message has been successfully submitted and would be delivered to recipients shortly.