Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find pattern and replace with everything after pattern vim

Tags:

regex

vim

I have a file which has contents like so:

size is X1 Identifier is Y1
size is X1 Identifier is Y1
size is X1 Identifier is Y1

I want to re-arrage the file so that I get

Identifier is Y1 size is X1 
Identifier is Y1 size is X1 
Identifier is Y1 size is X1 

How do I do this using vim find & replace? Or any other function in vim?

like image 595
sshirgao Avatar asked Dec 07 '22 17:12

sshirgao


1 Answers

Use capturing groups and switch both groups

%s/\v(.*) (I.*)/\2 \1
like image 149
Lieven Keersmaekers Avatar answered Jan 04 '23 23:01

Lieven Keersmaekers