Find the template and replace it with everything after the vim template

I have a file with the following contents:

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

I want to re-create the file to get

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

How can I do this with vim find and replace? Or any other function in vim?

+4
source share
4 answers

Use capture groups and switch both groups.

%s/\v(.*) (I.*)/\2 \1
+6
source

As you say, “Or any other function in vim,” I suggest an alternative by writing a macro. Personally, I like to use macros for such things, because you perform one action that you want to do once, which will help you think through exactly what you want, and then just repeat the same thing as many times as you need .

, , , , .

.

q a ( a - a )

0 ( )

, , : 3 d w - , , .

$ ( )

a SPACE ESC p ( , , )

j ( , , )

q ( )

, , , . , , :

@ a ( , a).

+4

vim , , , " regex", . .

, :

+2

:%s/\(size is \w*\) \(Identifier is \w*\)/\2 \1/g . , , X1, Y1, , \w*.

+2

Source: https://habr.com/ru/post/1682898/


All Articles