ilansh
ilansh

Reputation: 113

vi search and replace , puts a search result into other field in the same line

Hi I have a file full of strings

create_net_shape -no_snap -type path -net VDD -layer M9 -datatype 0 -path_type 0 -width 0.4 -route_type user_enter -points {{2965.64 302.835} {2979.93 302.835}}

I would like to be able to search and replace in vi , a certain field based on a result of other filed

I nedd the output to be

create_net_shape -no_snap -type path -net VDD -layer M9 -datatype 9 -path_type 0 -width 0.4 -route_type user_enter -points {{2965.64 302.835} {2979.93 302.835}}

and so on

how can I use my search result in one field and apply it into the other

thanks

Upvotes: 0

Views: 141

Answers (1)

kev
kev

Reputation: 161914

Try this command:

:%s/\v-layer M([0-9]+) -datatype \zs[0-9]+/\1/

  • The pattern will match digits right after -datatype.
  • We substitute these digits with those right after -layer M
  • Some advanced features. You can read the vimdoc with :help \v and :help \zs

Upvotes: 1

Related Questions