Line numbers for every cell in VSCode Jupyter Notebook Cells

Viewed 19431

In the normal Jupyter notebooks, we can add line numbers by pressing the L key after selecting the cell. All the subsequent cells for that notebook will have line numbers automatically.

But this is missing in VSCode. Every time a new cell is created, we need to select the cell and press the L key to enable the numbering for that cell which is very tiresome.

Is there a way to automatically enable line numbering for all the cells in the VSCode Jupyter notebook instead of manually pressing the L key for each and every cell?

Thank you.

8 Answers

In VS Code Jupyter Notebook, you can toggle line numbers by pressing L. The trick is to select the current cell first. You could select your cell by clicking in the blank area on the left margin of the cell (when it's selected the bar on the left turns blue). Now if you press L on your keyboard, you would be able to turn the line numbers on/off.

  1. Click on the blank area (left side of the cell).
  2. Press Shift + L.

Coming in v1.56: https://code.visualstudio.com/updates/v1_56#_toggle-line-numbers

You can now temporarily toggle the line numbers of a cell in the current session from the cell toolbar, or change the visibility of line numbers for all notebooks through the notebook.lineNumbers setting.

Under the ... in the floating menu is a line number toggle. [The gif is too large for SO.]

release notes cell line numbers

I always try any combination with modifiers keys. Found out that pressing Shift + L enables the lines number for all the notebook at once

Adding to this as still comes out the top result for the problem without a proper solution.

Assuming you have the Jupyter Notebook extensions installed for VSCode, in version 1.62.3, you can go into the Settings (Ctrl+,) search for "line numbers" and find the option for "Notebook:Line Numbers" and toggle this on.

This will show line numbers for all code cells in the Notebook by default so no need to keep pressing L

screen shot of Notebook line number toggle option

I tried CTRL + A (outside cells): select all cells and right clicked "show cell line number". It displayed line number for every cell.

Adds example for @mark answer, you can enable for current work space using:

  1. Make new folder name .vscode
  2. Make a setting file inside that folder called settings.json
  3. Copy paste code in the bottom of this post.
{
    // other setting can be placed here
    "notebook.lineNumbers": "on"
}
Related