如何在JupyterLab中显示代码行号?(附Jupyter Notebook操作参考)
How to Show/Hide Line Numbers in JupyterLab
I get it—switching between classic Jupyter Notebook and JupyterLab can throw off your muscle memory for shortcuts! Here are a few easy ways to toggle or set line numbers permanently in JupyterLab:
1. Using the UI Menu
This is the most straightforward method if you don’t want to memorize another shortcut:
- Open your JupyterLab notebook.
- Click on the View menu in the top bar.
- Look for the option labeled Show Line Numbers—click it to toggle line numbers on or off. A checkmark will appear next to it when enabled.
2. Keyboard Shortcut
JupyterLab uses a different default shortcut than the classic Notebook for this action:
- On Windows/Linux: Press
Ctrl + Shift + Lto toggle line numbers. - On Mac: Press
Cmd + Shift + Linstead.
If this shortcut doesn’t work for you, or you want to customize it to match the classic Notebook’s Ctrl + m L, you can adjust it:
- Go to Settings > Keyboard Shortcuts in the top menu.
- In the search bar, type "line numbers" to find the "Toggle Line Numbers" command.
- Click the pencil icon next to it, press your desired key combination, and save the change.
3. Set Line Numbers to Always Show by Default
If you want line numbers enabled every time you open a notebook, set this in the advanced settings:
- Go to Settings > Advanced Settings Editor.
- In the left sidebar, select Notebook under the "Settings" section.
- In the right panel (User Preferences), add the following line inside the curly braces:
"lineNumbers": true - Click the "Save Settings" button at the top right. From now on, all new and existing notebooks will display line numbers automatically.
Hope these methods help you get back to coding smoothly!
内容的提问来源于stack exchange,提问作者Saran
相关产品推荐
相关产品推荐

