VCode is a focused VS Code extension for macro automation: load, manage, and run macros directly in your editor.
- Built-in macro library shipped with the extension - useful macros with zero setup
- Macro Playground for rapid experimentation
- File-based macros from
.vscode/macro - Quick execution on selection or whole document
- Built-in commands to add, edit, delete, and refresh macros
- Create a macro file in
.vscode/macro/uppercase.js. - Paste this content:
module.exports = (context) => {
return context.input.toUpperCase();
};- Open Command Palette and run
VCode: Execute Macro. - Pick
uppercaseand see the selection change.
VCode ships with a library of common macros (snippets/macros in the extension), loaded automatically at startup. They appear alongside your own macros in VCode: Execute Macro and in the Macro Playground, tagged as Built-in.
Run VCode: Browse Built-in Macros to pick one by category and then choose to:
- Run on selection - apply it right away
- Copy to workspace - save an editable copy in
.vscode/macro - Open source - read the bundled script
- Copy code to clipboard
The library covers text and line operations (sort, dedupe, trim, join), encoding (URL, base64), JSON (format, minify, escape), naming (camelCase <-> snake_case), SQL (format, IN list), JavaScript helpers (try/catch, template literal, console.log), and date conversion. All built-in macros are JavaScript, so they run in-process without any interpreter.
Built-in macros are read-only. To customise one, copy it to your workspace and edit the copy.
{
"vcode.macro.builtins.enabled": true,
"vcode.macro.builtins.exclude": ["Format SQL", "base64-encode.js"]
}VCode: Execute MacroVCode: Add MacroVCode: Edit MacroVCode: Delete MacroVCode: Refresh MacrosVCode: Open Macro PlaygroundVCode: Browse Built-in MacrosVCode: Copy Built-in Macro to WorkspaceVCode: Reload Built-in Macros
You can configure VCode settings in your .vscode/settings.json or User Settings.
{
"vcode.macro.directories": [
".vscode/macro"
],
"vcode.macro.globals": {
"author": "Ada Lovelace",
"apiBase": "https://example.com"
},
"vcode.macro.python.path": "/path/to/venv/bin/python3",
"vcode.macro.perl.path": "/usr/bin/perl",
"vcode.macro.builtins.enabled": true,
"vcode.macro.builtins.exclude": []
}Macros can be written in JavaScript, Python, or Perl. JavaScript/Python macros return a string; Perl macros write the result to stdout.
Context Object:
input: Selected text, or the entire document if nothing is selected.languageId: VS Code language ID (example:typescript).filePath: Absolute path of the active file.globals: Global variables fromvcode.macro.globals.
JavaScript macros should define a transform function.
function transform(input, context) {
return input.toUpperCase();
}Python macros are .py files in .vscode/macro and must define transform(input, context, *args).
def transform(input, context, *args):
return input.upper()Python macros run with the configured interpreter. Set vcode.macro.python.path if you need a specific virtualenv or interpreter. If unset, VCode uses the Python extension's default interpreter or falls back to python3.
Perl macros are .pl files in .vscode/macro and should be standalone programs. VCode sends the selected text to stdin and reads the transformed output from stdout.
Set vcode.macro.perl.path if you need a specific Perl interpreter.
Environment variables:
VCODE_LANGUAGE_IDVCODE_FILE_PATHVCODE_GLOBALS_JSONVCODE_CONTEXT_JSONVCODE_PARAMS_JSONNote:VCODE_CONTEXT_JSONincludes metadata (languageId, filePath, globals). The input text is provided via stdin.
#!/usr/bin/env perl
use strict;
use warnings;
local $/;
my $input = <STDIN> // q{};
print $input;Open Macro Playground from the Command Palette to run code quickly, save new macros, and load existing ones without leaving the editor. You can choose the runtime (JavaScript, Python, or Perl) before running or saving.
VCode runs macros locally inside the VS Code extension host and does not send code or content to external services.
See CHANGELOG.md for details.
MIT