I'm trying to bulk correct some OCR formatting issues. I tried recording a macro that would:

  1. ]s (advance to the next spelling error)
  2. z= (view the suggested corrections)
  3. 1 (choose the first suggested correction)

Unfortunately for my purposes, when I replay the macro, it pauses at the step #3 and waits for me to make the selection. Is there a way to still automate that step too (as part of the macro or otherwise)?


  • 1
    Check help z= it takes a count
    – D. Ben Knoble
    May 10, 2019 at 0:40

2 Answers 2


The simple answer is to use a count as @Mass and @D.BenKnoble suggest:

  1. ]s
  2. 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:


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:


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:


  • +1 for the ^@ and ^J, i wish someone could explain this.
    – dedowsdi
    May 10, 2019 at 14:47

First assign the macro. Lets use register s:

:let @s="]sz=1\<cr>"

The special thing is \<cr>. This is Carriage Return that you need to hit after selecting the first spell sugestion.

As Mass & D. Ben Knoble pointed out, z= can take a count. So even simpler:

:let @s="]s1z="

Now use @s to execute the macro in register s. For the following invocations just use @@.

BTW: Be careful with this. I tested it on a text that contains the word "octothorpe". This was detected as spelling error and the first suggestion was "onto Thorpe".

  • 7
    why not just use 1z=?
    – Mass
    May 9, 2019 at 20:58
  • @Mass thats what i thought when i saw the question.
    – D. Ben Knoble
    May 9, 2019 at 22:59
  • @Mass, D.BenKnoble updated. Thanks for the hint.
    – Ralf
    May 10, 2019 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.