You could make a mapping like this:
noremap <Leader><C-A> :<C-U>execute 'normal!' str2nr(getreg('r')) . '<C-A>'<CR>
It maps \Control-A (
<Leader> defaults to \, see
:help leader) to run the usual Control-A the number of times specified in the
r register. You could even use this to rebind the default Control-A (leave out
<Leader>), but that seems like it could lead to confusion later if you ever forget about the mapping.
r register contains
5, it works like this (switched to double-quote notation since it is impossible to represent Control-A in a single-quoted string literal):
str2nr() functions are evaluated, resulting in this Ex command:
:execute 'normal!' 5 . "\<C-A>"
This results in another Ex command:
This executes a normal-mode command:
Which uses the prefix count before the usual Control-A (non-mapped, due do the
This version always uses the value in the
r register; it explicitly ignores any prefixed count (unlike the usual Control-A). Alternate implementations are possible (e.g. where a prefixed count overrides or multiplies the value in the
r register), but they would be a bit more complex.
You could also put the command directly in your macro instead of using a mapping:
qq…:execute 'normal!' str2nr(getreg('r')) . 'Control-A'Return…
You have to type the actual Control-A and Return instead of their
<> equivalents because this is no longer part of a mapping where Vim will automatically make the translation. Also, the Control-U is dropped, since it was only there to guard against a possible prefix count before the initial : (you can protect against this in the macro content itself).