2

I am trying to do a search and replace in vim (rather, gvim) and keep getting stuck up trying to separate words.

I need to convert something like this:

(COND <ASEL&~ASELb|XOR|~XORb> ( 

To this:

(COND ASEL=1'b1 && ASELb=1'b0 || XOR=1'b1 || XORb=1'b1 ( 

Basically, every occurrence of these 'words' has to be changed this way:

~ABC --> ABC=1'b0 ABC --> ABC=1'b1 

I have tried something like this to do it but can't get the pattern to match:

s/\([<&|]\)\~\([^<&|]\)\([>&|]\)/\1\2==1'b0\3 s/\([<&|]\)\([^<&|=]+\)\([>&|]\)/\1\2==1'b1\3 

The idea behind this was to do one 'word' at a time by separating it out in \2 above and then printing \1 and \3 as is with \2=1'b0 or \2=1'b1.

And then take care of the rest, like '&' going to '&&', removing the '<..>' at the ends in the subsequent commands.

What am I doing wrong here? Is there a better way to go about this?

1 Answer 1

0

see if this works...

(COND <ASEL&~ASELb|XOR|~XORb> ( #step 1 s/\v[<&|]\zs\u+/&=1'b1/g (COND <ASEL=1'b1&~ASELb|XOR=1'b1|~XORb> ( #step 2 s/\v[<&|]\zs\~(\u+b)/\1=1'b0/g (COND <ASEL=1'b1&ASELb=1'b0|XOR=1'b1|XORb=1'b0> ( #step 3 s/[&|]/ && /g (COND <ASEL=1'b1 && ASELb=1'b0 || XOR=1'b1 || XORb=1'b0> ( #step 4 s/[<>]//g (COND ASEL=1'b1 && ASELb=1'b0 || XOR=1'b1 || XORb=1'b0 ( 
  • \v is very magic mode so that (), + etc doesn't need to be escaped
  • \zs to set start of match

as one-liner

s/\v[<&|]\zs\u+/&=1'b1/g | s/\v[<&|]\zs\~(\u+b)/\1=1'b0/g | s/[&|]/ && /g | s/[<>]//g 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.