21
  • In JupyterLab, given the following code cell, how may it be split into multiple cells?

enter image description here

  • Likewise, given the following cells, how may they be combined into a single cell?

enter image description here

2 Answers 2

32

When working directly with JupyterLab, not in an IDE.

enter image description here

  • JupyterLab: splitCell
  • In order to split one cell into many cells:
    • Place cursors where the split is desired, and then press and release ctrl + shift + -
    • Multiple cursors may be placed, by holding ctrl, and clicking the location for the cursor.

enter image description here

  • JupyterLab: mergeCells
  • In order to merge multiple cells, into one cell:
    • Select the desired, consecutive cells, by holding shift, and clicking in the margin, where the [ ] is, which will highlight the selected cells.
    • While still holding shift, press m, and then release both keys.

enter image description here


Resources

0
7

For those that come here for Jupyter in VSCode, you can merge cells by:

  1. Selecting the cells (using shift + arrow is supported)
  2. Right click > Join With Previous Cell (or Join With Next Cell)

Join With Previous Cell key: Shift+Alt+Windows+J

Join With Next Cell key: Alt+Windows+J


NOTE: that it will join the selected range + previous or next cell. So, if you just want to merge two cell, no need to select using shift + arrow.

1
  • 1
    You can also recreate the default shortcut for jupyter by going to your keyboard shortcuts and setting shift+m for notebook.cell.joinSelected (Notebook: Join selected cells). If you open the json file through the command palette, you can set the when trigger to "when": "notebookEditorFocused".
    – Mr. Duhart
    Sep 12 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.