Skip to content
| Marketplace
Sign in
Visual Studio Code>Notebooks>Notebook: Run SelectionNew to Visual Studio Code? Get it now.
Notebook: Run Selection

Notebook: Run Selection

Christof Kaufmann

|
4 installs
| (1) | Free
Execute selected code directly in a notebook cell, like "Jupyter: Run Selection/Line in Interactive Window" but for notebooks.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Notebook: Run Selection

Notebook: Run Selection/Line runs selected code (or the current line) in a notebook cell — like Jupyter: Run Selection/Line in Interactive Window, but for notebooks. Useful when running an entire cell is too coarse and you just want to execute a sub-expression or a few lines.

Usage

Selecting code in a notebook cell and pressing Shift+Enter executes the selected code

  1. Open a Jupyter notebook (.ipynb).
  2. Click into a code cell and select the code you want to run.
  3. Press Shift+Enter (if the keybinding does not work, see below). You need to grant kernel access once.

The selected code is executed in the existing kernel. The output replaces the current output of the active cell.

If nothing is selected and you execute the command using the command palette, the current line is used, but the keybinding Shift+Enter is only active with a selection.

[!IMPORTANT] The command Notebook: Execute Cell and Select Below may take priority over Shift+Enter. User keybindings have an even higher priority, so add this to the list [...] in your keyboard shortcuts file keybindings.json:

    {
        "key": "shift+enter",
        "command": "nb-run-selection.runSelectionOrLine",
        "when": "editorHasSelection && notebookCellEditorFocused && !interactiveEditorFocused"
    },

Configuration

Setting Type Default Description
nbRunSelection.showExceptionsAsNotification boolean false Show kernel exceptions as a notification popup. Set to false to render them as cell output instead.

License

MIT

Original Issue

This extension serves as a workaround for issue microsoft/vscode#200625.

Known issues:

  • Currently, this extension cannot start a kernel.
  • The keybinding is conflicting with Notebook: Execute Cell and Select Below, which should only be triggered if there is no selection.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft