In Vim, how to swap 2 non adjacent patterns?

Posted by ThG on Stack Overflow See other posts from Stack Overflow or by ThG
Published on 2012-10-02T20:28:10Z Indexed on 2012/10/02 21:37 UTC
Read the original article Hit count: 149

Filed under:
|

I have lines of text, all with the same structure, and would like to make a permutation of 2 elements on all lines:

1257654 some text (which may be long) #Foo
1543098 some other text #Barbar
1238769 whatever #Baz
2456874 something else #Quux

I want to obtain :

#Foo some text (which may be long) 1257654
#Barbar some other text 1543098
#Baz whatever 1238769
#Quux something else 2456874

This is where I am stuck :

:%s/\(\d\{7\}\)\(#.\{-}\)/\2\1/

Where did I go wrong ?

© Stack Overflow or respective owner

Related posts about regex

Related posts about vim