Reputation: 911
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
Reputation: 101
In VSCode:
Here you can configure line number settings for your notebook.
Upvotes: 10
Reputation: 4600
In order to toggle on/off showing the line number for all the cells(code):
Upvotes: 160
Reputation: 41
Enter empty space on Jupiter notebook .ipynb file
Click:
F1
Then write:
Show Cell File Numbers
Upvotes: 1
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.]
Upvotes: 11
Reputation: 2147
Adds example for @mark answer, you can enable for current work space using:
.vscode
settings.json
{
// 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:
Preferences: Open User Settings (JSON)
or Preferences: Open Default Settings (JSON)
Upvotes: 2
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
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
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
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
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
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