vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Macro like keybindings

Open TheColorRed opened this issue 11 years ago • 68 comments

When creating keyboard shortcuts, it would be nice if you could pass an array of commands (to execute like a macro) that would run the commands in that order.

So take this for example:

{
    "key": "ctrl+s",
    "command": [
        "editor.action.format",
        "editor.action.trimTrailingWhitespace",
        "workbench.action.files.save"
    ],
    "when": "editorTextFocus"
}

It would format the file, remove trailing white space then save the file.

TheColorRed avatar Dec 01 '15 16:12 TheColorRed

Abolutely what I was thinking! - another example (mine)

{
    "key": "winl+b",
    "command": [
        "workbench.action.tasks.terminate",
        "workbench.action.tasks.build"
    ]
}

erichiller avatar Jul 08 '16 15:07 erichiller

love this idea

geddski avatar Nov 15 '16 20:11 geddski

Show any plain text in addition to commands will be great:

For example, using ctrl+; to move to the end of line and add ; and then move to the next line.

{
    "key": "ctrl+;",
    "commands": [
        "cursorEnd",
        ";",
        "editor.action.insertLineAfter"
    ],
    "when": "editorTextFocus"
}

amkgo avatar Nov 15 '16 23:11 amkgo

I'm surprised to see so few votes on this issue. I was looking for a way to bring up a terminal and hide the file explorer at the same time, since the integrated terminal doesn't occupy 100% width, and it seems vscode does'nt support multiple commands on a single keybindings yet. :(

Also, #6617 for ref.

fbnlsr avatar Feb 27 '17 10:02 fbnlsr

+1

faceyspacey avatar Mar 11 '17 20:03 faceyspacey

+1

bstro avatar Mar 15 '17 05:03 bstro

+1

liuhaopen avatar Mar 17 '17 12:03 liuhaopen

Hi guys, I've just found out the extension macros which is exactly I was looking for. Hope this helps you overcome this limitation.

ThisIsManta avatar Mar 18 '17 19:03 ThisIsManta

You probably want to allow arguments, for example when using the type command:

{
    "key": "ctrl+;",
    "commands": [
        {
             "command": "cursorEnd"
        },
        {
             "command": "type",
             "args": { "text": ";" }
        }
    ]
    "when": "editorTextFocus"
}

dvf avatar May 10 '17 18:05 dvf

If anyone on the core team would flag this with "help wanted" or "good first issue" i'd love to help out !

drKnoxy avatar Nov 13 '17 18:11 drKnoxy

Ok so this isn't really answer to issue in vscode, but one work around i found was to use autohotkey.

weeksdev avatar Nov 15 '17 19:11 weeksdev

FYI, I know this is slightly off-topic but for anyone using their machine to code and as a gaming platform: autohotkey can trigger video games anti-cheat programs. If you don't want to get kicked/banned during your next session of battlefield, be sure to have autohotkey turned off before playing. :)

fbnlsr avatar Nov 23 '17 08:11 fbnlsr

Bump. This would be very very helpful.

isaiahtaylor avatar Dec 19 '17 23:12 isaiahtaylor

I'd also love to have this feature :)

jsardev avatar Jan 16 '18 08:01 jsardev

Is this workable now? I want to customize vscode suggestion selection just like Visual Studio "select" and "print . or ("

visitantz avatar Jan 25 '18 09:01 visitantz

When could we have this feature :(

chestnutchen avatar Jan 30 '18 06:01 chestnutchen

Use case: comment/uncomment line and move cursor down like in IntelliJ IDEA.

  {
    "key": "cmd+/",
    "command": ["editor.action.commentLine", "cursorDown"],
    "when": "editorTextFocus && !editorReadonly"
  }

Nowaker avatar Feb 13 '18 06:02 Nowaker

Another use case is to locate the file in file explorer and make the file explorer active like resharper.

    {
        "key": "shift+alt+l",
        "command": ["workbench.files.action.showActiveFileInExplorer", "workbench.view.explorer"]
    }

Jontem avatar Feb 13 '18 09:02 Jontem

You can currently do this using the multi-command vscode extension! 😃

jessedvrs avatar Feb 14 '18 12:02 jessedvrs

+1, surprised that this generic feature does not exist in the base vscode

moymike avatar Mar 06 '18 14:03 moymike