Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Record and Play Back Macros in VS Code

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

VS Code does not have a built-in macro recording feature, so you cannot natively record and replay sequences of edits. To achieve macro functionality, you need to install a third-party extension like "Macro" by edam9999 or "multi-command". Once installed, you can record a sequence of actions (like typing, navigating, and deleting) and replay them with a single command. This guide covers how to set up and use macro recording in VS Code using the widely adopted "Macro" extension.

What You'll Need

  • Visual Studio Code (version 1.40 or newer, though using the latest stable version is recommended)
  • Internet connection (to install the extension from the VS Code Marketplace)
  • The "Macro" extension by edam9999 (free, available in the Extensions view)

Step-by-Step

  1. Open VS Code and go to the Extensions view by clicking the square icon on the left sidebar (or press Ctrl + Shift + X / Cmd + Shift + X on macOS).
  2. In the Extensions search box at the top, type macro and press Enter.
  3. Locate the extension titled "Macro" (publisher: edam9999), and click the Install button. Wait for installation to complete—no reload is required.
  4. After installation, open any file you want to work on (e.g., a JavaScript or Python file).
  5. Press Ctrl + Shift + P (or Cmd + Shift + P on macOS) to open the Command Palette.
  6. Type macro start record and select the command Macro: Start Recording from the list. VS Code will display a status bar message: "Recording macro..." (usually in the bottom-right).
  7. Perform the sequence of actions you want to record. For example:
    • Press End to move to the end of the line
    • Type // comment
    • Press Enter to go to the next line
    • Press Ctrl + Home to return to the top of the file
    Every cursor movement, text insertion, and deletion is captured.
  8. When finished, press Ctrl + Shift + P again, type macro stop record, and choose Macro: Stop Recording. The status bar will confirm "Macro recorded successfully." ote that the macro is saved temporarily and will be lost if VS Code closes unless you save it (see Step 8).
  9. To save the macro for future use, open the Command Palette again, type macro save, and select Macro: Save Recorded Macro. VS Code will prompt you to enter a name for the macro (e.g., "add-comment-and-newline"). Type a descriptive name and press Enter. The macro is now stored in your user settings.
  10. To run the saved macro, open the Command Palette, type macro play, and select Macro: Play. A dropdown menu will appear listing all saved macros—choose your recorded macro to execute it.
  11. Optionally, assign a keyboard shortcut to your macro for faster access: press Ctrl + K then Ctrl + S to open Keyboard Shortcuts, search for macro.play, click the pencil icon next to the command, and press your desired key combination (e.g., Ctrl + M).

Common Mistakes

  • Recording while the Command Palette is open—actions inside the palette are not captured, but opening it during recording may cause unexpected cursor jumps.
  • Forgetting to stop recording before closing VS Code: unsaved macros are lost on restart.
  • Recording global actions (like switching tabs or opening files) that assume a specific workspace setup—macros replay in the current context, so they may behave differently if the file structure or cursor position differs.
  • Overlooking that macros do not record mouse clicks—only keyboard-driven navigation and text input (e.g., clicking line numbers won’t be captured).
  • Recording undo/redo sequences: macros replay the original actions, not the undo state, so undoing during recording does not eliminate the recorded action.

Tips

  • Keep macros short and focused (3–10 steps) for reliability—complex macros are more likely to break when replayed in new contexts.
  • Use Ctrl + Shift + P > macro list to see all saved macros and verify they are stored correctly.
  • When editing a saved macro, open your user settings (Ctrl + , > gear icon > Open Settings (JSON)), search for macro, and locate the macro.macro section to manually edit JSON entries.
  • For repetitive edits across many files, open each file, place the cursor where needed, and run the macro—no need to re-record.
  • Test your macro on a duplicate or non-critical file first to catch issues before applying it widely.
  • Combine with the "multi-command" extension if you need to chain multiple macros or trigger commands not captured during recording.

Troubleshooting

  • "Recording" status doesn’t appear: Ensure the extension is enabled (Extensions view > search "macro" > check the toggle). Restart VS Code if needed.
  • Macro doesn’t replay correctly: Verify the macro was saved—unsaved recordings vanish after closing VS Code. Re-record and save again. Also confirm the cursor position and file content differ from what was recorded, as macros replay relative to current context.
  • Command not found in Command Palette: Type "macro" in the palette to filter commands; if missing, reinstall the extension or try Developer: Reload Window from the palette.
  • Macro stops mid-execution: Check if the macro included a command that requires user input (e.g., a find/replace dialog). Simplify the macro to avoid interactive prompts.
  • Recording ignores text deletions: Ensure you’re using standard editing keys (Backspace, Delete, Ctrl + Backspace)—some custom keybindings may not be captured.

Frequently Asked Questions

Does VS Code support native macro recording without extensions?

No. VS Code does not include macro recording in its core feature set. A third-party extension is required.

Are macros saved permanently?

Yes—if you use Macro: Save Recorded Macro to assign a name. They are stored in your user settings JSON file and persist across VS Code restarts.

Can I record macros across multiple files?

You can record actions across files, but the macro will replay in the context of the currently active file. It does not automatically open or switch between files unless you explicitly included those steps.

Do macros work with snippets or extensions like Emmet?

Yes. If you type a snippet trigger (e.g., ! + Tab) or use an extension command (e.g., Emmet) during recording, it will be included and replayed.

Is there a limit to how long a macro can be?

There is no strict limit, but very long macros (>200 steps) may become fragile. For extensive automation, consider writing a small VS Code extension instead.

Can I record audio or video inside VS Code?

No. Macro recording only captures editor actions (text, cursor movements, and basic commands)—not screen activity, audio, or external actions.