Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change edit mode shortcuts in Jupyter notebooks?

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?

like image 914
Gaurav Bansal Avatar asked Jul 24 '20 21:07

Gaurav Bansal


People also ask

How do you change to edit mode in Jupyter Notebook?

Edit mode. When a cell is in edit mode, you can type into the cell, like a normal text editor. Enter edit mode by pressing Enter or using the mouse to click on a cell's editor area.

How do I change keyboard shortcuts in Jupyter?

Starting with Jupyter Notebook 5.0, you can customize the command mode shortcuts from within the Notebook Application itself. Head to the ``Help`` menu and select the ``Edit keyboard Shortcuts`` item. A dialog will guide you through the process of adding custom keyboard shortcuts.

How do I get out of Edit mode in Jupyter Notebook?

To Exit Edit Mode into Command mode, hit ESC.

How to edit a Jupyter notebook using keyboard?

Starting with IPython 2.0, the Jupyter Notebook has two modes: command mode. Keyboard will behave differently depending upon which mode you have selected. Green cell border is an indication of whether edit mode is enabled or not. You can switch from command mode to edit mode by pressing Enter key, turning cell border colour to green.

What are the different modes in Jupyter Notebook?

Jupyter Notebook Modes There are two modes in Jupyter. These are edit mode and command mode. If the cell has a green border, that means you’re in edit mode.

What is the difference between command and edit mode in Jupyter?

There are two modes in Jupyter. These are edit mode and command mode. If the cell has a green border, that means you’re in edit mode. If the cell has a blue border, then you’re in command mode. Edit mode is for all the actions you would usually perform in the context of the cell.

How to add Markdown to a Jupyter Notebook?

Thanks to Markdown cells, you are able to add text to Jupyter Notebooks.By using the Cell menu or toolbar, or key shortcut m, you can change cell types to Markdown.Markup language Markdown comes in a very popular version, a set of markup languages. How Do You Write On A Jupyter Notebook?


1 Answers

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.

like image 112
bodily11 Avatar answered Sep 19 '22 19:09

bodily11