Last updated: Apr 10, 2024
Reading time·5 min
The easiest way to show or hide the line numbers in Jupyter Notebook is to:
Esc
key to enter command mode.L
key to toggle the line numbers.Ctrl
+ M
key combination to enter command mode and then press L
to toggle the line numbers.When you press Esc
(or Ctrl
+ M
), the left border should become blue. This
is when you should press L
.
Note that pressing Esc
and then L
only shows the line numbers for the
current cell.
You can press Esc
and then press Shift
+ L
to toggle the visibility of the
line numbers for all cells.
If you use Jupyter Lab, simply press Shift
+ L
to toggle the visibility
of the line numbers.
You can also use the Command Palette to show the line numbers:
Ctrl
+ Shift
+ P
(or Cmd
+ Shift
+ P
on macOS).If you only want to show the line numbers for the current cell, click on toggle line numbers.
Notice that there are also hide all line numbers and show all line numbers commands that aren't bound.
Here is a short clip that demonstrates how this works.
If you need to view a list of all of the available keyboard shortcuts:
Ctrl
+ m
and release the keys.h
.You can also use the top menu to show or hide the line numbers:
If you use JupyterLab, you can show the line numbers by default by editing your settings.
Click on Settings and then click on Advanced configuration.
Click on the JSON settings editor button in the top right corner of the Advanced Settings Editor to show the User Overrides editor.
Add the following code in the User Overrides editor to the right.
{ "codeCellConfig": { "lineNumbers": true } }
To show the line numbers in Jupyter Notebook in VS Code:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
You can also show the line numbers in Jupyter Notebook in VS Code by editing your settings.json file.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
"notebook.lineNumbers": "on",
Make sure to remove the trailing comma if the property comes last.
You can use a local settings.json
file if you only want to show the Jupyter
Notebook line numbers for the current project.
In the root directory of your project, create a .vscode
folder.
Create a settings.json
file in the .vscode
folder.
Add the following code to your settings.json
file.
{ "notebook.lineNumbers": "on" }
Note that any settings you add to your local .vscode/settings.json
file only
apply to the current project and override any global configuration.
You can learn more about the related topics by checking out the following tutorials: