'Any way to swap Enter and Shift-Enter input commands in Edit-Mode, Jupyter Notebook?
I just started using ipython/jupyter notebook. The Shift-Enter (run current cell) and Enter (insert newline) commands are frustrating to use. I would like to swap the commands for those two inputs in edit-mode.
So:
Shift-Enter: (insert newline)
Enter: (run current cell)
Is there some way to remap commands for jupyter notebook? A config file maybe? It sounds like ipython notebook did not always work this way (Enter in the IPython console inserts new line instead of executing current line after kernel restart #2696). The solution to the linked github issue seems to be "just use shift-enter," and I was unable to find a solution on google.
I have the following versions:
ipykernel (4.5.2)
ipython (5.3.0)
jupyter (1.0.0)
notebook (4.4.1)
Solution 1:[1]
EDIT:
On newer JupyterLab (I'm now on 2.2.5), there's now a Keyboard Shortcuts settings file (under Settings > Advanced Settings Editor). Unfortunately, it seems that a swap between Shift+Enter and Enter is no longer possible, so that when adding Enter as a run-current-cell key, Shift+Enter still runs the current cell (i.e., if one adds Enter as a run-current-cell key, it can no longer add a new line in the current cell).
OLDER ANSWER:
An old question, but worth an answer for people using JupyterLab (Version 0.35.6, Windows 10):
- Go to Settings > Advanced Settings Editor. A Settings tab will open.
- On the sidebar of the Settings tab, click Keyboard Shortcuts. Two inner-tabs will open: System Defaults and User Overrides.
- Copy the following into User Overrides to replace Shift+Enter with Enter (note that there's no need to explicitly define Shift+Enter as the keyboard shortcut for "new line").
The actual override here is the value "Enter", which replaces the default value "Shift Enter":
{
"runmenu:run": {
"command": "runmenu:run",
"keys": [
"Enter"
],
"selector": "[data-jp-code-runner]",
"title": "Run",
"category": "Run Menu"
},
"notebook:run-cell-and-select-next": {
"command": "notebook:run-cell-and-select-next",
"keys": [
"Enter"
],
"selector": ".jp-Notebook.jp-mod-editMode",
"title": "Run Cell and Select Next",
"category": "Notebook Operations"
}
}
- Hit the save icon on the upper right corner.
End result:
Solution 2:[2]
Open up a notebook, and under [Help] you can find [Edit Keyboard Shortcuts]. For versions before 5.0, the documentation I linked below has a detailed explanation as to what command you can run to change the shortcuts.
Solution 3:[3]
Extending upon the answer by @OfirD, it seems that the following keyboard shortcuts user preference JSON does the trick in recent versions of JupyterLab:
{
"shortcuts": [
{
"args": {},
"command": "notebook:run-cell-and-select-next",
"keys": [
"Shift Enter"
],
"selector": ".jp-Notebook.jp-mod-editMode",
"disabled": true
},
{
"args": {},
"command": "notebook:run-cell-and-select-next",
"keys": [
"Enter"
],
"selector": ".jp-Notebook.jp-mod-editMode",
},
{
"args": {},
"command": "runmenu:run",
"keys": [
"Shift Enter"
],
"selector": "[data-jp-code-runner]",
"disabled": true
},
{
"args": {},
"command": "runmenu:run",
"keys": [
"Enter"
],
"selector": "[data-jp-code-runner]",
},
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | fractals |
| Solution 3 | Wayne |

