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

how to change the second match in a S&R?

Expand Messages
  • Jeri Raye
    Hi, How do you change the second matching pair in stead of the first one. I have the following substitute but I can t get it in such a way that it works on the
    Message 1 of 3 , Jul 5, 2009
      Hi,

      How do you change the second matching pair in stead of the first one.
      I have the following substitute but I can't get it in such a way that
      it works on the second pair.

      :g/\<INPUT.*,*s\d\+/s/s\d\+/(&)/<CR>

      So
      INPUT s1 , s2
      INPUT s2 , s1

      must come

      INPUT s1 , (s2)
      INPUT s2 , (s1)

      Rgds,
      Jeri

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Zsolt Udvari
      ... Imho s@INPUT ([^ ]* ) , ([^ ]* )@INPUT 1 ( 2)@ Zsolt --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use
      Message 2 of 3 , Jul 5, 2009
        > How do you change the second matching pair in stead of the first one.
        > I have the following substitute but I can't get it in such a way that
        > it works on the second pair.
        >
        > :g/\<INPUT.*,*s\d\+/s/s\d\+/(&)/<CR>
        >
        > So
        > INPUT s1 , s2
        > INPUT s2 , s1
        >
        > must come
        >
        > INPUT s1 , (s2)
        > INPUT s2 , (s1)

        Imho s@INPUT \([^ ]*\) , \([^ ]*\)@INPUT \1 (\2)@

        Zsolt


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tim Chase
        ... You can use ... -tim --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more information,
        Message 3 of 3 , Jul 5, 2009
          > How do you change the second matching pair in stead of the first one.
          > I have the following substitute but I can't get it in such a way that
          > it works on the second pair.
          >
          > :g/\<INPUT.*,*s\d\+/s/s\d\+/(&)/<CR>
          >
          > So
          > INPUT s1 , s2
          > INPUT s2 , s1
          >
          > must come
          >
          > INPUT s1 , (s2)
          > INPUT s2 , (s1)

          You can use

          :%s/INPUT\s\+[^,]*,\s*\zs.*/(&)

          -tim



          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.