Srikanth Vaindam
Srikanth Vaindam

Reputation: 455

How to substitute part of an expression in vim using substitute

How do I put a part of search pattern in substitution string.

I have to replace abc->hwqe_w1_len with common_wqe_get_len(abc)
Similarly this one def->hwqe_w1_len with common_wqe_get_len(def)

using only one expression in vim substitute command.

I tried using the following command but it says invalid command.
:%s /\(.*\)->hwqe_w1_len/\='common_wqe_get_len(' . submatch(1) '\)'/gc

When I remove the closing brace it works, but it takes the spaces before abc
:%s /\(.*\)->hwqe_w1_len/\='common_wqe_get_len(' . submatch(1)/gc

What is the mistake I am doing? How do I put abc with out spaces and the closing brace at the end?

Upvotes: 1

Views: 474

Answers (1)

JJoao
JJoao

Reputation: 5367

:%s/\(\w*\)->hwqe_w1_len/common_wqe_get_len(\1)/g

Upvotes: 5

Related Questions