Reputation: 5660
In a Jupyter Notebook I can click on Help -> Edit Keyboard Shortcuts to change Command Mode shortcuts. However, I don't see how I can change Edit Mode shortcuts. How can I do this?
Upvotes: 7
Views: 3178
Reputation: 604
You are correct that Help -> Edit Keyboard Shortcuts will only change Command Mode shortcuts (at least as of Nov 2020). In fact, at the bottom of the edit keyboard shortcuts modal for Jupyter Notebook it states "Changing the keybindings of edit mode is not currently available."
So to get to the "edit" shortcuts I had to go into the notebook config. Documentation here: https://jupyter-notebook.readthedocs.io/en/stable/extending/keymaps.html
For me, the notebook config was located here "~/.jupyter/nbconfig/notebook.json". Once there, you can bind (set new shortcuts) or unbind (remove existing shortcuts).
Here is the structure of my notebook.json file:
{
"Cell": {
"cm_config": {
"lineNumbers": false
}
},
"keys": {
"command": {
"bind": {
"ctrl-enter": "jupyter-notebook:run-cell"
}
},
"edit": {
"bind": {
"ctrl-enter": "jupyter-notebook:run-cell"
}
}
}
}
Notice how I want to run cells with Ctrl-enter rather than Cmd-enter, so I am binding Ctrl-enter to run cells in command mode and edit mode. I'm on a Mac but have previously gotten used to Ctrl-enter to run cells, so I wanted to change things back.
Once you have modified your notebook.json file, restart Jupyter Notebook and your shortcuts should work!
If you are wondering where to find the code syntax name for each action, there is a command palette (tiny keyboard at the top middle right of Jupyter Notebook). After you click into it, hover over the command mode key on the right side and it will give you a little tooltip with the code syntax name.
Upvotes: 5