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

Re: Swapping two elements around a third

Expand Messages
  • Gumnos (Tim Chase)
    ... Sounds like tagged regex substitution statements are what you re hunting... ... So for your trivial case, ... will change abc to cba ... would change
    Message 1 of 2 , Mar 30 1:24 PM
    • 0 Attachment
      > generically
      > abc
      > to
      > cba
      > where a, b and c can possibly be quite long, and not simple words.

      Sounds like tagged regex substitution statements are what you're hunting...

      :s/\(1st item regex\)\(pivot item regex\)\(2nd item regex\)/\3\2\1

      So for your trivial case,

      :s/\(a\)\(b\)\(c\)/3\2\1

      will change "abc" to "cba"

      However, you can do more powerful stuff like:

      :s/\([^& ]*\)\(\s*&&\s*\)\(.*\)/\3\2\1

      would change "foo && bar" to "bar && foo"

      This can be applied over a whole document or over a range, depending on what
      you feed to the :s (:%s/... or :'a,'bs/... or whatever)

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