Gowrishankar S Nath
Gowrishankar S Nath

Reputation: 911

Line numbers for every cell in VSCode Jupyter Notebook Cells

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.

Upvotes: 91

Views: 67591

Answers (11)

Berkay Cihan
Berkay Cihan

Reputation: 101

In VSCode:

  1. Press Ctrl+Shift+P to open the Command Palette.
  2. Type "open user settings" and select Preferences: Open User Settings.
  3. In the Search Settings, type "notebook: line numbers".

Here you can configure line number settings for your notebook.

Line Number Settings

Upvotes: 10

Hadij
Hadij

Reputation: 4600

In order to toggle on/off showing the line number for all the cells(code):

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

Upvotes: 160

Elina Eliel
Elina Eliel

Reputation: 41

Enter empty space on Jupiter notebook .ipynb file

Click:

F1

Then write:

Show Cell File Numbers

Upvotes: 1

Mark
Mark

Reputation: 181559

There is an unbound command to toggle line numbers:

notebook.cell.toggleLineNumbers

BTW, beginning in v1.75 the setting

notebook.lineNumbers  can show relative line numbers 

VS Code can now use all editor line number options when notebook.lineNumbers is turned on. For example, with "notebook.lineNumbers": "on" and "editor.lineNumbers": "relative", relative line numbers are displayed in cell editor.

from v1.75 Release Notes: Cell Editor Polish


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

Upvotes: 11

Muhammad Yasirroni
Muhammad Yasirroni

Reputation: 2147

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"
}

Edit:

To open settings.json without manually creating the file is by opening workspace or user settings:

  1. open Command Palette (Ctrl+Shift+P)
  2. Type Preferences: Open User Settings (JSON) or Preferences: Open Default Settings (JSON)
  3. Copy paste the snippet setting.

Upvotes: 2

Daniel Kuenstler
Daniel Kuenstler

Reputation: 21

As for 2022:

In the upper left corner, select the config-weel. One of the options you can choose is 'Show Notebook Line Numbers' Sweet and easy.enter image description here

Upvotes: 2

adheir
adheir

Reputation: 11

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

Upvotes: 1

user17571854
user17571854

Reputation: 321

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

Upvotes: 32

Daniele S DShot92
Daniele S DShot92

Reputation: 79

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

Upvotes: 7

Tom Hale
Tom Hale

Reputation: 46823

As of 2021-01-04, this is sadly not possible.

Subscribe to the GitHub issue (Feature Request) Line Numbers - All Cells #1593 for updates.

Related: Line numbers should be enabled for current cell and subsequent cells when turned on #1659

Upvotes: 7

Kumar Nishant
Kumar Nishant

Reputation: 751

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.

Upvotes: 60

Related Questions