The simple answer is to use a count as @Mass and @D.BenKnoble suggest:
]s
1z=
But let's take a closer look at why your original macro was failing, because it's not quite as simple as @Ralf implies.
First try recording your steps into register "r
:
qr]sz=1Enterq
Then use @Ralf's :let
command to set up register "s
:let @s="]sz=1\<cr>"
And then take a look at the difference in the output of :registers
:
"r ]sz=1^M
"s ]sz=1^M^J
When you were recording your macro, you pressed Enter, and you can see that it's been included in the "r
register as a CTRL-M
or CR
character. (As you may already know, pressing CTRL-M and pressing Enter within a terminal does the same thing, for historical reasons.)
However, when you set the "s
register directly with the :let
command, the \<CR>
carriage return has been included as a CTRL-M
followed by a CTRL-J
(CRLF
). I have no idea why there is a difference or why the LF
is required for the macro to work, but let's try re-recording the macro and this time pressing CTRL-J after pressing Enter to see if we can include this character in our recording:
qr]sz=1EnterCTRL-Jq
Now let's take another look at the :registers
output again:
"r ]sz=1^M^@
"s ]sz=1^M^J
Okay. Not quite right: pressing CTRL-J seems to have inserted a NUL
character into our macro instead of a LF
. (Again, no real idea why this is.) Still, try running the new macro, and you will discover that it works!
Extra Credit:
Now let's make the macro recursive so we can correct the entire file with a single @q:
qqqqq]sz=1EnterCTRL-J@qq