GithubHelp home page GithubHelp logo

macros's Introduction

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",
],

macros's People

Contributors

geddski avatar ctf0 avatar dependabot[bot] avatar al-th avatar hyh19962008 avatar runofthemill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.