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:


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:


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


see if this works...


#step 1
(COND <ASEL=1'b1&~ASELb|XOR=1'b1|~XORb> (

#step 2
(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
(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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.