Skip to content

ctf0/macros

 
 

Repository files navigation

Macros

Brings simple, powerful custom macros support to VS Code. Made with <3 by geddski

See also Level up your Coding with Macros

based on macrosRe + New Features

Original

Create your custom macros by adding them to your settings.json (Code|File > Preferences > User Settings)

For example:

"macros.list": {
    "commentDown": [
        "editor.action.copyLinesDownAction",
        "cursorUp",
        "editor.action.addCommentLine",
        "cursorDown"
    ]
}

This macro creates a copy of the current line, comments out the original line, and moves the cursor down to the copy.

Your macros can run any built-in VS Code action, and even actions from other extensions. To see all the names of possible actions VS Code can run, see Default Keyboard Shortcuts (Code|File > Preferences > Keyboard Shortcuts)

Give your macros names that briefly describe what they do.

Add Keybindings to Run your Macros

in keybindings.json (Code|File > Preferences > Keyboard Shortcuts) add bindings to your macros:

{
  "key": "ctrl+cmd+/",
  "command": "macros.commentDown"
}

Notice that macros.my_macro_name has to match what you named your macro.

Passing Arguments to Commands

Many commands accept arguments, like the "type" command which lets you insert text into the editor. For these cases use an object instead of a string when specifying the command to call in your settings.json:

"macros.list": {
  "addSemicolon": [
    "cursorEnd",
      {"command": "type", "args": {"text": ";" }}
  ]
}

Reference of VScode commands that needs arguments can be found in Built-in Commands. Note that simple-commands that can be found in the Keyboard Shortcuts list doesn't use argument : Built-in Commands#simple-commands.

Executing Snippets As Part Of A Macro

Macros can also execute any of your snippets which is super neat. Just insert the same text that you would normally type for the snippet, followed by the insertSnippet command:

"macros.list": {
  "doMySnippet": [
    {"command": "type", "args": {"text": "mySnippetPrefixHere" }},
    "insertSnippet"
  ]
}

New

Run macro From command pallet

simply use Ctrl+P or Alt+P depend on your os, and type Macros:Execute then chose the macro you want to execute.

Run Commands With A Delay

"macros.list": {
    "createNewTabAndPaste": [
        "workbench.action.files.newUntitledFile",
        {
            "command": "$delay",
            "args": {
                "delay": 50
            }
        },
        "editor.action.clipboardPasteAction"
    ]
}

Run A Command Times Another Command #48

"macros.list": {
    "undoCommentDown": [
        {
            "command": "undo",
            "args": {
                "command": "commentDown"
            }
        }
    ]
}

Repeat A Command #36

"macros.list": {
    "commentDown10": [
        {
            "command": "commentDown",
            "args": {
                "times": 10
            }
        }
    ]
}

In/Ex-clude Commands From The Quick Picker "allow take precedence over ignore"

"macros.list": {
    "delay-100": [
        {
            "command": "$delay",
            "args": {
                "delay": 100
            }
        }
    ],
    "some-other-cmnd": [
        // ...
    ],
},
"macros.qp-allow": [
    "some-other-cmnd",
],
"macros.qp-ignore": [
    "delay-100",
],

About

macros support for VS Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

  • TypeScript 100.0%