It seems that there is no built-in way to do what I want. So I came up with this small chunk of code following @DjMcMayhem comment. It is not extensively tested but it seems to be working.
First let's remap
@ to call our custom function:
nnoremap <silent> @ :<C-U>call MacroWithCount()<CR>
And the function:
# Get the content of a register given by the user
let registerContent = getreg(nr2char(getchar()))
let macroCount = v:count1
for i in range(macroCount)
execute "normal! " . registerContent
let macroCount = macroCount - 1
First we use
getreg() combined with
getchar() to get the content of a register given by the user.
Then we create the
macroCount variable which will be the variable to use in the macro to get the current count.
Finally we execute the macro and update
macroCount each time the macro has been executed once.
Now if I record this macro:
12 11 10 9 8 7 6 5 4 3 2 1
Note that the function still needs a major improvement: it doesn't understand
execute the last executed macro. so far I haven't found a way to get the content of the last executed macro (I thought that it was what
v:register was for but it seems that I was wrong)
The related help topics: