microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.78k stars 28.18k forks source link

Macro like keybindings #871

Open TheColorRed opened 8 years ago

TheColorRed commented 8 years ago

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.

erichiller commented 8 years ago

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

{
    "key": "winl+b",
    "command": [
        "workbench.action.tasks.terminate",
        "workbench.action.tasks.build"
    ]
}
geddski commented 7 years ago

love this idea

amkgo commented 7 years ago

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"
}
fbnlsr commented 7 years ago

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.

faceyspacey commented 7 years ago

+1

bstro commented 7 years ago

+1

liuhaopen commented 7 years ago

+1

ThisIsManta commented 7 years ago

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

dvf commented 7 years ago

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

{
    "key": "ctrl+;",
    "commands": [
        {
             "command": "cursorEnd"
        },
        {
             "command": "type",
             "args": { "text": ";" }
        }
    ]
    "when": "editorTextFocus"
}
drKnoxy commented 6 years ago

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

weeksdev commented 6 years ago

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

fbnlsr commented 6 years ago

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. :)

isaiahtaylor commented 6 years ago

Bump. This would be very very helpful.

jsardev commented 6 years ago

I'd also love to have this feature :)

visitantz commented 6 years ago

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

chestnutchen commented 6 years ago

When could we have this feature :(

Nowaker commented 6 years ago

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

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

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"]
    }
jessedvrs commented 6 years ago

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

moymike commented 6 years ago

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

ianha commented 6 years ago

Please add this feature, very much needed!

tomer-yoskovich commented 6 years ago

Until we'll have it in vscode, thanks @jessedvrs, with this extension I was able to create a keybinding for a common operation 1) save all files 2) git refresh (another open vscode issue is that you have to click 'refresh' manually sometimes) 3) commit all files (it opens a popup to enter the commit message)

userSettings:

"multiCommand.commands": [
        {
            "command": "multiCommand.quickGitCommit",
            "sequence": [
                "workbench.action.files.saveAll",
                "git.refresh",
                "git.commitAll",
            ]
        }
    ]

keybindings.json

{ 
        "key": "F4", 
        "command": "multiCommand.quickGitCommit", 
        "when": "editorTextFocus"
}
PragmaticEd commented 6 years ago

Maybe someone can explain to me, what i'm doing wrong, cos this doesn't seem to work for me: default keybindings - person_name - visual studio code administrator 2018-06-07 11 36 45

bersbersbers commented 6 years ago

@PragmaticEd why is multiCommand.commands underlined in green? Have you installed the right extension, https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command? (Maybe this is not the right place to discuss this - what would be a better one?)

PragmaticEd commented 6 years ago

@bersbersbers I found another, even nicer-looking, solution in plugin called macros

After installing plugin:

In user settings:

{
   "macros": {
        "commentAndMoveDown": [
            "editor.action.commentLine",
            "cursorDown",
            "cursorLineStart"
        ]
    }
}

in keybindings.json

[
 {
    "key": "ctrl+shift+c",
    "command": "macros.commentAndMoveDown"
  }
]
mackcoding commented 6 years ago

how is this not a feature yet?

PragmaticEd commented 6 years ago

@mackcoding I feel like it should be..

dwilches commented 5 years ago

Not a feature yet?

In the mean time, one can use macros.

ghost commented 5 years ago

much needed feature, should be native.

Nukium commented 5 years ago

needed here ! :)

Outpox commented 5 years ago

Still looking for this feature.

kkwillmert commented 5 years ago

Would love this feature as well. Would also like to see it in Azure Data Studio (where the 'macros' extension is NOT available), which clearly shares a common ancestry with VSCode :-)

bingoabs commented 5 years ago

I like it and like goto next end function maybe can achive like this: { "key": "shift+enter", "command": ["cursorDown", "cursorEnd"], "when": "editorTextFocus" }

thu-san commented 5 years ago

+1 pls :)

eliliam commented 5 years ago

2019 is asking why this feature is still not added yet! @sandy081, @joaomoreno and others working on the keybindings, this Issue was opened in 2015, that's four full years of development time not spent adding an extremely useful and seemingly simple feature. The back end of the keybindings API could just concatenate the listed commands and run them one after another. Please add this, there is no official fix besides using extensions for a very basic feature!

fifn2 commented 5 years ago

Please add this! I really need this feature.

SunXuan90 commented 5 years ago

Please add this!

RecursiveCarrot commented 5 years ago

Another use case:

Hide both sidebar and activity bar at the same time:

 {
        "key": "ctrl+s",
        "command": ["workbench.action.toggleSidebarVisibility", "workbench.activity.toggleActivityBarVisibility"]
   }
johnculviner commented 5 years ago

Would love to see this get added as well. This allows for ultimate editor flexibility. We already have "when" context on keybindings why not multiple commands!

njkevlani commented 5 years ago

I know it is not what we guys want, but this is the work-around I'm using right now. tasks-api can take commands #11396 and we can combine multiple tasks using dependsOn.

So... In tasks.json

  "tasks": [
    {
      "label": "save_file",
      "command": "${workbench.action.files.save}"
    },
    {
      "label": "command2",
      "command": "${command2}"
    },
    {
      "label": "save_and_command2",
      "dependsOn": [
        "save_file",
        "command2"
      ]
    }

To set a keybinding to this task In keybindings.json

    {
        "key": "ctrl+shift+f10",
        "command": "workbench.action.tasks.runTask",
        "args": "save_and_command2"
    }
dovry commented 4 years ago

Is there any work being done for this or has it not been put on the TODO list because there are extensions for it?

amelio-vazquez-reina commented 4 years ago

@njkevlani What do you think it's the main benefit of using tasks.json for this over e.g. macros? I guess one could argue that tasks.json is at least natively supported by VSCode? Anything else you could think of? [Thanks for the tip by the way!]

njkevlani commented 4 years ago

@amelio-vazquez-reina

Initially, I was configuring something to save and run a file. I configured a task for that. Later on, I wanted to get a keybinding for that and then I came across this issue and #11396 in the same time interval (I don't remember how) and felt this might be a work around for this as well.

I guess one could argue that tasks.json is at least natively supported by VSCode?

That's one more positive :)

naturalbornchiller commented 4 years ago

+1

EugeneDae commented 4 years ago

Bind one key to multiple commands via user level tasks, no extensions required. Not a perfect way, but it works.

liuchangyu1988 commented 4 years ago

I would love to have this feature too!!

atrifex commented 4 years ago

Would love to see this in production :)

liangjiancang commented 3 years ago

And array for key:

{
    "key": [
        "ctrl+s",
        "ctrl+alt+l"
    ],
    "command": [
        "editor.action.format",
        "editor.action.trimTrailingWhitespace",
        "workbench.action.files.save"
    ],
    "when": "editorTextFocus"
}
trevorphillipscoding commented 3 years ago

Anything like this yet? Would love it!

drozumek commented 3 years ago

I'd love to see this feature is VS Code.