Search code examples
regexvimsubstitution

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 "=")


Solution

  • Try this:

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

    or:

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

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