User-invokable commands can be added to the menus and command palette, optionally with keyboard key-equivalents. These commands invoke a callback registered in the JavaScript execution environment of the extension.

Defining a Command

The extension’s extension.json can include a commands object defining which commands are exposed by the extension.

The commands object can contain several “sections” that commands may be defined:


    "identifier": "com.panic.HTML",
    "name": "HTML",
    "vendor": "Panic Inc.",
    "main": "main.js",
    "commands": {
        "editor": [
                "title": "Wrap Selection In Tag",
                "command": "wrapSelectionInTag",
                "shortcut": "cmd-<",
                "when": "editorHasFocus",
                "filters": {
                    "syntaxes": ["html"]

This defines a command, “Wrap Selection In Tag”, that when invoked by the user will invoke the wrapSelectionInTag command handler registered in the extension’s JavaScript environment. Registration of the command handler is done like so:

// Wraps the current editor selection in a new tag, with placeholders
nova.commands.register("wrapSelectionInTag", (editor) => {
    var selectedRanges = editor.selectedRanges.reverse();
    editor.edit(function(e) {
        for (var range of selectedRanges) {
            var text = editor.getTextInRange(range);
            var newText = "<$[tag]>" + text + "</$[tag]>";
            e.replace(range, newText);

Each command can be configured using a number of options:

When Clauses

The when clause of extension commands is an expression that defines under what circumstances a command should be enabled. The expression format follows a strict subset of standard JavaScript conditional syntax. The variables available within these expressions is dependent on the context in which the extension is available.


Variables in When Clauses

The set of available variables for various contexts in when expressions are:

Editor Context
documentHasPath The document has a path, representing a file on disk (as opposed to an untitled file)
editorHasFocus The editor is the focused pane and is first responder
editorHasSelection The editor has at least one non-zero-length selected range
editorHasMultipleSelections The editor has at least two or more selections (including multiple cursors)
editorSyntax Evaluates the editor syntax name against a string (editorSyntax == 'javascript')
ViewItem Context
viewItem The contextValue for the item(s) that are currently selected

Separator Items

For both the Extensions and Editor menu contexts (commands placed within the extensions and editor groups of the commands manifest key), you can optionally include separator items to better group your commands.

To define a separator, add an object with the following form:

{"separator": true}

These can be placed anywhere in your commands array, provided that two separators are not adjacent to each other and they do not appear at the head and tail of the menu.