Tushar
Tushar

Reputation: 499

Can I search and replace with mathematical expression in Vim?

I have a following line:

set_property LOC DSP48E2_X0Y0 [get_cells{name[0].dut/mm1/dsp_chain[0].dsp_inst}];

I want to replace DSP48E2_X0Y{number} to DSP48E2_X0Y{number+5} I followed a thread on Stack overflow and I tried to use awk command:

echo "set_property LOC DSP48E2_X0Y0   [get_cells {name[0].dut/mm1/dsp_chain[0].dsp_inst}];" | awk `{ printf "%s %s %s_X%dY%d", $1, $2, $3, $4, $5+5}`

but I am getting errors:

bad math expression: operand expected at `,'

Upvotes: 2

Views: 235

Answers (1)

melpomene
melpomene

Reputation: 85897

To answer the question in your title: Yes, just start the replacement with \=.

In your case,

:s/DSP48E2_X0Y\zs\d\+/\=submatch(0)+5/

would do it.

(No idea what all that awk stuff is about.)

Upvotes: 3

Related Questions