How to move Jupyter notebook cells up/down using keyboard shortcut?

The following solution works on JupyterLab (I currently have version 2.2.6):

You must first open the Keyboard Shortcuts configuration file. In JupyterLab you can find it in Settings -> Advanced Settings Editor then selecting the “Keyboard Shortcuts” option in the left panel and then editing the “User Preferences” tab at the right.

Expanding on sherdim’s answer, you must add two json objects (one for each direction) within the “shortcuts” json array. Here I have chosen the shortcuts Ctrl + Shift + ↓ and Ctrl + Shift + ↑.

{
    "shortcuts": [
        {
            <<other items you may have>>
        },
        {
            "command": "notebook:move-cell-up",
            "keys": [
                "Ctrl Shift ArrowUp"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "command": "notebook:move-cell-down",
            "keys": [
                "Ctrl Shift ArrowDown"
            ],
            "selector": ".jp-Notebook:focus"
        },
    ]
}

Finally, press Ctrl + S to save changes.

Now, when you are in the command mode, you should be able to move one or more selected cells up or down. The shortcuts will even appear in the menu Edit -> Move Cells Up and Edit -> Move Cells Down.

Leave a Comment

tech