2

I'm trying to repeat register couple of times and assign it to another register whilst concatenating the strings.

For example:

let @d = '<td></td>'
let @r = '<tr>' . 10@d . '</tr>'
let @t = '<table>' . 10@r . '</table>'

However this syntax is not allowed.

Is there any different syntax or workaround to achieve that without repeating n-times?

1 Answer 1

6

There's the repeat() function:

repeat({expr}, {count})
Repeat {expr} {count} times and return the concatenated result.

Example usage:

:let @d = '<td></td>'
:let @r = '<tr>' . repeat(@d, 3) . '</tr>'
:let @t = '<table>' . repeat(@r, 2) . '</table>'

:echo @r
<tr><td></td><td></td><td></td></tr>

:echo @t
<table><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></table>

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.