Coder Social home page Coder Social logo

waltergr / vscode-editor-macros Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jsnee/vscode-editor-macros

0.0 0.0 0.0 196 KB

Visual Studio Code extension that provides a lightweight solution to VSCode's lack of custom macros

License: GNU General Public License v3.0

TypeScript 100.00%

vscode-editor-macros's Introduction

vscode-editor-macros

Visual Studio Code extension that provides a lightweight solution to VSCode's lack of custom macros.

This extension is heavily inspired by geddski's macros extension.

Usage

There are two main types of macros you can create:

  • Command-based
  • String replacement Create your own custom macros by adding them to your settings.json (Code|File > Preferences > User Settings)

Command Macros

Exactly like the macros extension, you can chain together a series of commands to run in succession:

{
    "editormacros": {
        "addSemicolon": {
            "type": "command",
            "args": {
                "commands": [
                    "cursorEnd",
                    { "command": "type", "args": { "text": ";" } }
                ]
            }
        }
    }
}

String Replacement

This extension also leverages string replacement as another way to design macros. You can configure string replacement as such:

{
    "editormacros": {
        "convertTabsToSpaces": {
            "type": "replace",
            "args": {
                "regex": true,
                "replaceAll": true,
                "multiline": false,
                "searchPattern": "\t",
                "replacePattern": "    "
            }
        }
    }
}

Note: "regex", "replaceAll", and "multiline" aren't required, but will both default to false if not provided. If "regex" is true, the "searchPattern" will be treated as a regular expression. "multiline" enables the multiline flag.

Multiple Typed Macros

If you want to chain multiple string replacements or combine commands with string replacements, you can use the "third" macro type: "multiple":

{
    "editormacros": {
        "deserialize": {
            "type": "multiple",
            "args": {
                "macros": [
                    {
                        "type": "replace",
                        "args": {
                            "regex": true,
                            "searchPattern": "^'",
                            "replacePattern": ""
                        }
                    },
                    {
                        "type": "replace",
                        "args": {
                            "regex": true,
                            "searchPattern": "'$",
                            "replacePattern": ""
                        }
                    },
                    {
                        "type": "replace",
                        "args": {
                            "regex": true,
                            "replaceAll": true,
                            "searchPattern": " ",
                            "replacePattern": "\n"
                        }
                    }
                ]
            }
        }
    }
}

Configuring Keybindings

Just like the macro extension, once your macros are setup, you can bind them to macros in keybindings.json (Code|File > Preferences > Keyboard Shortcuts):

[
    {
        "key": "ctrl+alt+shift+;",
        "command": "editormacros.addSemicolon"
    }
]

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.