如何设置Jupyter Notebook运行单元格后默认进入编辑模式?
Adjust Jupyter Notebook's Shift+Return to Enter Edit Mode Below
Absolutely, you can tweak this setting to make Shift+Return drop you straight into edit mode in the next cell—no extra clicks needed! Here are two straightforward ways to do it:
Method 1: Use the GUI Shortcut Editor (Easiest)
- Open your Jupyter Notebook and switch to command mode (press
Escif you’re typing in a cell). - Click the Help menu at the top, then select Edit Keyboard Shortcuts. This opens a panel for customizing key bindings.
- In the search bar, type "run cell and select below"—this is the default action tied to
Shift+Return. - Instead of modifying the existing action, let’s create a new custom one that does exactly what you want:
- Click the Add Shortcut button.
- In the "Action" field, paste this combined command:
run-cell-and-select-next, enter-edit-mode - Click the "Shortcut" field and press
Shift+Returnto assign this key combo. - Hit Save to apply the change.
Now, when you press Shift+Return, it’ll run the current cell, jump to the next one, and immediately put you into edit mode—perfect!
Method 2: Edit the Custom JS File (For Advanced Users)
If the GUI method doesn’t work for your Jupyter version, you can modify the custom.js file directly:
- Locate your Jupyter config directory (usually
~/.jupyter/custom/on macOS/Linux, orC:\Users\YourName\.jupyter\custom\on Windows). - Open
custom.jsin a text editor, and add this code:require(["base/js/namespace", "base/js/events"], function(Jupyter, events) { Jupyter.keyboard_manager.command_shortcuts.add_shortcut('shift-enter', { help : 'Run cell and enter edit mode in next cell', handler : function (event) { Jupyter.notebook.execute_cell_and_select_next(); Jupyter.notebook.edit_mode(); return false; } }); }); - Save the file and restart your Jupyter Notebook server for changes to take effect.
Either method should fix the behavior you’re frustrated with.
内容的提问来源于stack exchange,提问作者Greg
相关产品推荐
相关产品推荐

