Skip to content

command add

Add a command registered in the command palette, with optional menu entry, keybinding, and when clause.

Terminal window
vsceasy command add --name sayHello --title "Say Hello"

Flags

FlagTypeNotes
--nametextRequired. Command id (camelCase).
--titletextPalette title. Defaults to PascalCase of name.
--categorytextOptional category prefix shown in the palette.
--menuEntrytextInsert into this menu (file basename in src/menus/).
--grouptextParent group label inside the menu.
--iconcodiconIcon shown next to the menu entry.
--keybindingtextKeyboard shortcut, e.g. ctrl+shift+h.
--whentextwhen clause controlling palette enablement.

Examples

Terminal window
# simple palette command
vsceasy command add --name sayHello --title "Say Hello"
# with a menu entry, icon, and keybinding
vsceasy command add \
--name doStuff \
--title "Do Stuff" \
--menuEntry main \
--group Actions \
--icon play \
--keybinding "ctrl+alt+d"
# only enabled when an editor has focus
vsceasy command add --name format --title "Format" --when editorTextFocus

when clause cheatsheet

ClauseMeaning
editorTextFocusactive text editor
editorHasSelectiontext is selected
resourceLangId == typescriptcurrent file language
resourceExtname == .jsoncurrent file extension
explorerResourceIsFolderfolder selected in Explorer
workspaceFolderCount != 0a workspace is open
view == myExt-settingsinside a specific tree view
viewItem == myCtxtree item with that contextValue
!virtualWorkspaceexclude github.dev / codespaces

Operators: && || ! == != =~ in. Full reference: when-clause contexts.

src/commands/sayHello.ts
import { defineCommand } from '../shared/vsceasy';
export default defineCommand({
title: 'Say Hello',
run: async (vscode) => {
await vscode.window.showInformationMessage('Hello!');
},
});