close

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

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to move Jupyter notebook cells up/down using keyboard shortcut in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

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

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

    You can select the next cell (downwards direction) – Shift + J or Shift + Down key and select cells to upwards direction using Shift + K or Shift + Up key.

  2. move Jupyter notebook cells up/down using keyboard shortcut

    You can select the next cell (downwards direction) – Shift + J or Shift + Down key and select cells to upwards direction using Shift + K or Shift + Up key.

Method 1

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.

Method 2

You can select the next cell (downwards direction) – Shift + J or Shift + Down key and select cells to upwards direction using Shift + K or Shift + Up key.

These short cuts I’ve tried windows only. For other OS, please refer to this source.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read