Tim Chase wrote:
[...]
I broke it out into multiple lines to hopefully make more sense of it. The first two substitute() lines add a zero on the left of whatever they found, and then take whatever the rightmost two characters of the result are...effectively padding them with zeros on the left if needed. Ideally, Vim would provide a right() function where you could just do something like

    right('0'.submatch(1), 2)

to zero-pad to 2 places. Alas, the substitute() trick is the easiest way I've found to simulate this.
[...]

        ("0" . submatch(1))[-2:]

i.e. the last two characters of the string obtained by prepending a zero to submatch(1)


see ":help expr-[:]"


Best regards,
Tony.

Reply via email to