关于JupyterLab是否支持跳转至先前活跃单元格功能的问询
JupyterLab: Jump Back to Previously Active Cell & Custom Shortcuts
Great question—this is such a common frustration, especially when you’re switching between edit and command mode quickly! Let’s break down how to solve both your use cases.
Does JupyterLab support returning to the previous active cell?
Yes, it does! JupyterLab has built-in commands for navigating back and forth between recently active cells. These are exactly what you need for both your scenarios:
- Scenario 1: After accidentally hitting Home/End and jumping to the top/bottom, you can instantly jump back to your last edited cell.
- Scenario 2: After running a quick calculation at the bottom of the notebook, you can bounce right back to your main code cell without scrolling manually.
You can access these commands via the Command Palette (press Ctrl/Cmd + Shift + P), then search for:
Navigate Back(to go to the previous active cell)Navigate Forward(to go forward if you’ve navigated back multiple times)
How to set custom shortcuts for these commands
By default, these navigation commands don’t have assigned shortcuts, but you can easily add them in JupyterLab’s settings:
- Open the Settings menu, then select Advanced Settings Editor.
- In the left sidebar, choose Keyboard Shortcuts.
- In the right pane, go to the User Preferences tab (you’ll see a JSON editor).
- Paste the following code into the editor to bind custom shortcuts. Feel free to adjust the keys to whatever works for you (I prefer
Ctrl+Alt+Left/Ctrl+Alt+Right, but you can use other combinations):
{ "shortcuts": [ { "command": "notebook:navigate-back", "keys": ["Ctrl Alt Left"], "selector": ".jp-Notebook" }, { "command": "notebook:navigate-forward", "keys": ["Ctrl Alt Right"], "selector": ".jp-Notebook" } ] }
- The
".jp-Notebook"selector ensures these shortcuts work in both Command Mode and Edit Mode, which is perfect for your use case. - If you only want the shortcuts to work in one mode, adjust the selector: use
".jp-Notebook.jp-mod-editMode"for edit mode only, or".jp-Notebook.jp-mod-commandMode"for command mode only.
- Click Save Settings (top-right corner) to apply the changes. Now you can use your new shortcuts to jump back and forth between cells instantly!
内容的提问来源于stack exchange,提问作者Mikhail Shevelev
相关产品推荐
相关产品推荐

