I am not sure why you think you need a variable, here.
Assuming the first macro, stored into register
b, looks something like:
:let @b = "^C<li>^R"</li>"
Then the second macro, stored in register
b, could look like this:
:let @a = "c<ul>^M</ul>^[P:.,']norm @b^M"
^M being produced with
^R produced with
^[ produced with
This should let you visually select the lines, say with
vip, and do
@b does the following:
- move the cursor to the first printable character of the line with
- change the rest of the line with
- insert the content of the unnamed register with
@a does the following:
- change the currently selected text with
<ul>, followed by a carriage return, followed by
- leaves insert mode with
- put the lines cut at step 1 above the current line with
@b on the lines we just changed with
:help '] is the last line of the last change. Since the last change left you on its first line, you can create a range that covers all the lines in the last change and execute the desired macro on all those lines without having to count them.