Coding⏱️ 3 min read📅 2026-06-11

How to Fix: vim: Continue macro after error in submacro?

Vim macro issue with error handling

Quick Answer: Use the `n` command to continue executing the macro after an error occurs.

The issue you're experiencing with vim macros is frustrating because it prevents you from executing complex sequences of commands. This error occurs when a submacro terminates due to an error, causing the wrapper macro to stop execution.

Don't worry; we can resolve this issue by modifying your wrapper macro to continue execution after a submacro generates an error.

🔍 Why This Happens

  • The root cause of this error is that vim's macro evaluation stops when it encounters an error in a submacro. To overcome this, you need to use the `&l` register and the `q@` command.
  • Another possible cause could be that the submacro is not properly defined or has an invalid pattern.

🚀 How to Resolve This Issue

Modifying the wrapper macro

  1. Step 1: Open your vim script file and navigate to the line where you want to execute the wrapper macro.
  2. Step 2: Use the `q@` command followed by the name of the submacro you want to call. For example, if you have a submacro named 'Macro 2', use `q@Macro 2`.
  3. Step 3: To continue execution after the submacro terminates, use the `&l` register and the `q@` command again. For example, `q@&lMacro 1` will execute Macro 1 after Macro 2 terminates.
  4. Step 4: Repeat this process for each macro in your sequence.

Alternative solution using the `q:` command

  1. Step 1: Alternatively, you can use the `q:` command to call a submacro and continue execution after it terminates. For example, `:q@Macro 1` will execute Macro 1 and then continue execution.
  2. Step 2: To stop execution of the wrapper macro when an error occurs in a submacro, use the `q@` command followed by the name of the submacro you want to call. For example, `q@Macro 2` will stop execution.

💡 Conclusion

By modifying your wrapper macro or using the `q:` command, you can resolve the issue and execute complex sequences of vim macros without interruption.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions