Jupyter lab shortcuts

二次信任 提交于 2019-12-02 18:24:38

This question is answered on GitHub here. You can also look here for the correct command names to enter in your keyboard shortcut user overrides because they are not always the same as what is shown in the Commands side-bar.

The following are some that I use:

{
  "notebook:collapse-selected-outputs": {
    "command": "notebook:hide-cell-outputs",
    "keys": [
      "O"
    ],
    "selector": ".jp-Notebook:focus"
  },    

  "notebook:expand-selected-outputs": {
    "command": "notebook:show-cell-outputs",
    "keys": [
      "O", 
      "O"
    ],
    "selector": ".jp-Notebook:focus"
  },    

  "notebook:clear-all-outputs": {
    "command": "notebook:hide-all-cell-outputs",
    "keys": [
      "Ctrl L"
    ],
    "selector": ".jp-Notebook:focus"
  },

  "notebook:collapse-all-code": {
    "command": "notebook:hide-all-cell-code",
    "keys": [
      "Shift O"
    ],
    "selector": ".jp-Notebook:focus"
  }
}

which allows you to hide a cell output by pressing O once and showing the cell output by pressing O twice. The last one collapses all cell code with Shift + O as you requested.

I use these settings to bind the actions to move a cell up/down to Ctrl + Up/Down:

{
    // Move cell up
    "notebook:move-cell-up": {
      "selector": ".jp-Notebook:focus",
      "command": "notebook:move-cell-up",
      "keys": [
        "Ctrl ArrowUp"
      ]
    },

    // Move cell down
    "notebook:move-cell-down": {
      "selector": ".jp-Notebook:focus",
      "command": "notebook:move-cell-down",
      "keys": [
        "Ctrl ArrowDown"
      ]
    }
}

You should edit the settings file in Settings/Keyboard Shortcuts. Here :

There you can specify any custom shortcut that you would like!

pX0r and plalanne's answers above combined worked for me with minor modification for Mac.

I hope this step-by-step iteration is helpful for someone like me who's a baby programmer. To summarize:

  1. Open Advanced Settings Editor under the Settings tab, or command , in Mac.
  2. Navigate to Keyboard Shortcuts. You should see the screen plalanne answered with.
  3. Use pX0r's codes, however making one change in the key binding as Ctrl Arrowup is reserved in Mac to view all running applications (if you have it set up that way). Similarly, Shift Arrowup is for selecting multiple cells. As a result, I opted for Alt Arrowup. Notice the key on your Mac keyboard says alt/option. You have to refer to it as Alt to work. There you have it. Copy the codes below to User Overrides which is the right pane.
  4. Re-open your notebook and test if it works as intended.
  5. You can customize more keys in this fashion as long as it is defined here on GitHub. For the most part, all that you need are the command IDs starting line 72.
{
    // Move cell up
    "notebook:move-cell-up": {
      "selector": ".jp-Notebook:focus",
      "command": "notebook:move-cell-up",
      "keys": [
        "Alt ArrowUp"
      ]
    },

    // Move cell down
    "notebook:move-cell-down": {
      "selector": ".jp-Notebook:focus",
      "command": "notebook:move-cell-down",
      "keys": [
        "Alt ArrowDown"
      ]
    }
}

If you cannot save the "User Preferences" settings and get a syntax error

[additional property error] command is not a valid property

you have probably missed to nest within the "shortcuts" list, as described here. Additionally, to override an old setting you do the following, using Activate Next Tab and Activate Previous Tab as examples:

{
    "shortcuts": [
        {
            "command": "application:activate-next-tab",
            "keys": [
                "Ctrl Shift ]"
            ],
            "selector": "body",
            "disabled": true  // disable old setting
        },
        {
            "command": "application:activate-previous-tab",
            "keys": [
                "Ctrl Shift ["
            ],
            "selector": "body",
            "disabled": true  // disable old setting
        },
        {
            "command": "application:activate-next-tab",
            "keys": [
                "Ctrl 1"  // enable new shortcut key
            ],
            "selector": "body"
        },
        {
            "command": "application:activate-previous-tab",
            "keys": [
                "Ctrl 2"  // enable new shortcut key
            ],
            "selector": "body"
        }
    ]
}

Now you can click save and refresh your browser for the new setttings to take effect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!