Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim Regex substitute question

I'm trying to replace in VIM all multiple "-" characters (from the start of lines) with "="

p.e. replace "-----" with "====="
or replace "----------" with "=========="

I created this regex:

%s/^-\{2,}/=  ????/g

Does anyone know how I can replicate the "=" substitution? (what do I have to put after "=")

like image 443
Reman Avatar asked Sep 13 '26 18:09

Reman


1 Answers

Try this:

:%s/^-\{2,}/\=substitute(submatch(0), '-','=','g')/

or:

:%s/^-\{2,}/\=repeat('=',len(submatch(0)))/

See :help sub-replace-\= for more details.

like image 152
Raimondi Avatar answered Sep 16 '26 07:09

Raimondi



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!