Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim regular expression substitution quantifier

how do i quantify the replacement portion of a vim search/replace expression?

:%s/x\{4\}/yyyy/g 

will replace every occurrence of 4 x's with 4 y's.

:%s/x\{4\}/y\{4\}/g 

replaces the 4 x's with "y{4}"

how do i modify that so that i do not have to insert 4 separate y's but instead "quantify" a single y.

like image 928
Amalafrida Avatar asked Jun 20 '26 05:06

Amalafrida


1 Answers

The solution seems more troublesome than its worth:

:%s/w\{4}/\=repeat('y',4)/g
like image 85
romainl Avatar answered Jun 22 '26 02:06

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!