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

sub-substitution

Expand Messages
  • Mikolaj Machowski
    Hello, I love :w !sh command and am doing most of filenames changes in that way (and other nice stuff). But I don t know hot to do something like this: name of
    Message 1 of 3 , Oct 1, 2002
    • 0 Attachment
      Hello,

      I love :w !sh command and am doing most of filenames changes in that
      way (and other nice stuff). But I don't know hot to do something like
      this:

      name of the directory/name of the file

      to

      name of the directory/name_of_the_file

      How I can make sub-substitution only on \2 (or \1)
      After reading docs I get this:

      :s#\(.*/\)\(.*\)#\=\1 . substitute(submatch(2), " ", "_", "g")

      but it doesn't work :(

      Mikolaj

      ps. This is rather simple example I'd like to make more complex
      substitutions with [], \d, \a and so on.
    • Brett Pershing Stahlman
      ... From: Mikolaj Machowski To: Sent: Tuesday, October 01, 2002 1:19 PM Subject: sub-substitution ... Try this instead (use
      Message 2 of 3 , Oct 1, 2002
      • 0 Attachment
        ----- Original Message -----
        From: Mikolaj Machowski <mikmach@...>
        To: <vim@...>
        Sent: Tuesday, October 01, 2002 1:19 PM
        Subject: sub-substitution


        > Hello,
        >
        > I love :w !sh command and am doing most of filenames changes in that
        > way (and other nice stuff). But I don't know hot to do something like
        > this:
        >
        > name of the directory/name of the file
        >
        > to
        >
        > name of the directory/name_of_the_file
        >
        > How I can make sub-substitution only on \2 (or \1)
        > After reading docs I get this:
        >
        > :s#\(.*/\)\(.*\)#\=\1 . substitute(submatch(2), " ", "_", "g")
        Try this instead (use submatch(1) instead of \1 in the expression register):

        s#\(.*/\)\(.*\)#\=submatch(1).substitute(submatch(2), ' ', '_', 'g')

        Hope this helps,
        Brett S.
        > but it doesn't work :(
        >
        > Mikolaj
        >
        > ps. This is rather simple example I'd like to make more complex
        > substitutions with [], \d, \a and so on.
        >
        >
      • Mikolaj Machowski
        ... Aha. Thanks :) m.
        Message 3 of 3 , Oct 1, 2002
        • 0 Attachment
          On Tue, 1 Oct 2002, Brett Pershing Stahlman wrote:

          > > name of the directory/name of the file
          > >
          > > to
          > >
          > > name of the directory/name_of_the_file
          > > :s#\(.*/\)\(.*\)#\=\1 . substitute(submatch(2), " ", "_", "g")
          >
          > s#\(.*/\)\(.*\)#\=submatch(1).substitute(submatch(2), ' ', '_', 'g')
          >

          Aha. Thanks :)

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