how to exactily repeat the n matched pattern in result string
Try this:
:%s/^+*/\=repeat(' ',strlen(submatch(0)))/
submatch(0)
contains all the matched +
at the start of the line, strlen
counts them. So for every plus sign at the start of the line three spaces are inserted using repeat
.
For more information:
:help sub-replace-expression
:help repeat()
:help submatch()
:help strlen()
An elegant substitution command for this case is the following:
:%s/\%(^+*\)\@<=+/ /g