Add a custom command in Visual Studio Code Command Palette
Asked Answered
F

6

27

Is it possible out of the box or using extensions to add a custom command in the Command Palette in Visual Studio Code like "External Tools" as in the IDE from JetBrains or in Visual Studio?

I would like to be able to run custom bash/cmd command directly from the Command Palette.

Fasces answered 22/5, 2018 at 16:42 Comment(0)
S
20

You can either use VS Code built-in functionality using shortcuts. Just add to keybindings.json:

{
  "key": "cmd+shift+R",
  "command": "workbench.action.terminal.sendSequence",
  "args": {
    "text": "clear; rails server\u000D"
  }
},

Or you can take a look at this extension: Command Runner

Slump answered 24/4, 2019 at 17:29 Comment(2)
how does the argument need to be specified if I want to wrap a selected text in the VS Code document with a prefix and suffix? e.g. turning text to \command{text}?Boardman
@Marie.P. The feature supports variable substitution.Repand
M
5

https://marketplace.visualstudio.com/items?itemName=usernamehw.commands

This extension can run it from custom Quick Pick (like command palette, but shows only your items). Command id is commands.openAsQuickPick


There's no api to seamlessly add commands to Command Palette #1422, but it's possible to modify package.json what that extension does when this setting is enabled:

"commands.populateCommandPalette": true,

With this setting it will not update Command Palette until the editor is reloaded. It might be an ok experience if you don't do that very often.

Maxiemaxilla answered 30/6, 2021 at 21:21 Comment(0)
C
4

You can use multiCommand Extention to build your custom commands, which you can access through the Command Palette. Ctrl+Shift+P > Multi command > custom command.

I know it's not ideal, but I guess you can open multi command with a key binding and then it's almost what you want. Plus the feature that you can execute multiple commands with this extension.

Corenecoreopsis answered 13/5, 2020 at 13:31 Comment(0)
C
1

Tasks allow you to run commands, either using tools that the project already has setup, e.g. make, ant or msbuild, or to run shell commands. You can then run these from the command pallete using Tasks: Run Task. For example a tasks.json file to run git mergetool on the current file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "git mergetool",
            "type": "shell",
            "command": "git mergetool ${file}",
            "problemMatcher": []
        }
    ]
}
Contactor answered 22/5 at 14:54 Comment(0)
N
-2

This guy wrote something where you can customize the toolbar. https://github.com/AdamAnandUS/AdamsTool

Maybe add to it with a new StatusBarItem that registers a command you want to run. https://code.visualstudio.com/docs/extensionAPI/vscode-api#commands.registerCommand

There are also many VS Code Extensions that might do what you want already. https://stackify.com/top-visual-studio-code-extensions/

Nippon answered 22/5, 2018 at 18:26 Comment(1)
unfortunately none of the above is suitableFasces
N
-6

Go to tools, External tools in visual Studio. Click Add, name the new command then you can point to a batch file command using the browse ellipses. When you save it, you will then see the new menu item under tools.

Nippon answered 22/5, 2018 at 16:50 Comment(1)
i need this for Visual Studio CodeFasces

© 2022 - 2024 — McMap. All rights reserved.