Add a custom command in Visual Studio Code Command Palette

32.4k Views Asked by At

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.

5

There are 5 best solutions below

1
On

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/

1
On

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.

0
On

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.

0
On

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.

2
On

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