Link Search Menu Expand Document





  • params
    • uri - (optional) Uri of the folder or workspace file to open. If not provided, a native dialog will ask the user for the folder
    • newWindow - (optional) Whether to open the folder/workspace in a new window or the same. Defaults to opening in the same window.


Command URIs

  • Commands URIs are links that execute a given command.
  • They can be used as clickable links in hover text, completion item details, or inside of webviews.
  • command URI uses the command scheme followed by the command name
    • eg: command:editor.action.addCommentLine


Commands support enablement via an enablement property - its value is a when-clause. Enablement applies to all menus and to registered keybindings.

when clause

Conditional operators

Equality=="editorLangId == typescript"
Inequality!="resourceExtname != .js"
Or||"isLinux || isWindows"
And&&"textInputFocus && !editorReadonly"
Matches=~resourceScheme =~ /^untitled$^file$/



Editor contexts

Context nameTrue When
editorFocusAn editor has focus, either the text or a widget.
editorTextFocusThe text in an editor has focus (cursor is blinking).
textInputFocusAny editor has focus (regular editor, debug REPL, etc.).
inputFocusAny text input area has focus (editors or text boxes).
editorHasSelectionText is selected in the editor.
editorHasMultipleSelectionsMultiple regions of text are selected (multiple cursors).
editorReadonlyThe editor is read only.
editorLangIdTrue when the editor's associated language Id matches. Example: "editorLangId == typescript".
isInDiffEditorThe active editor is a difference editor.
isInEmbeddedEditorTrue when the focus is inside an embedded editor.

Other Context

  • terminalFocus


How can I find out what command is bound to a specific key?

Keyboard Shortcut editor, you can filter on specific keystrokes to see which commands are bound to which keys. Below you can see that Ctrl+Shift+P is bound to Show All Commands to bring up the Command Palette.

How can I add a key binding for only certain file types?

  • Use the editorLangId context key in your when clause:
{ "key": "shift+alt+a",           "command": "editor.action.blockComment",
                                     "when": "editorTextFocus && editorLangId == csharp" }



execute a command

import * as vscode from 'vscode';

function commentLine() {

get result from cmd

import * as vscode from 'vscode';

async function printDefinitionsForActiveEditor() {
  const activeEditor = vscode.window.activeTextEditor;
  if (!activeEditor) {

  const definitions = await vscode.commands.executeCommand<vscode.Location[]>(

  for (const definition of definitions) {

create new command with arg inside extension.ts

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
  const command = 'myExtension.sayHello';
  const commandHandler = (name: string = 'world') => {
    console.log(`Hello ${name}!!!`);
  context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler));