Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo/redo changes inside the selected cell in Jupyter notebook?

I am using Jupyter notebook (from anaconda Jupyter lab) on Windows 10 and tried to undo/redo changes in the selected cell. However, I can only undo/redo changes in the whole notebook.

For example, I edited cell#1 then cell#2. Say I want to undo changes in cell#1, so I go to cell#1 and press control+z, it will however undo the change in cell#2.

My friend using Mac doesn't have this issue. Are there any settings for this? I searched online and didn't find anyone who has the same problem. It is so weird!

like image 262
s99090 Avatar asked Aug 12 '21 20:08

s99090


People also ask

How do you undo changes in a cell in Jupyter notebook?

If you click inside the cell you edited, pressing Ctrl-Z should undo the changes.

How do you undo double click in Jupyter notebook?

Click that white background and press <Shift+Enter> .


Video Answer


1 Answers

This global undo/redo is a new feature that enables Real Time Collaboration which was added in JupyterLab 3.1. It is indeed sub-optimal for many use cases.

JupyterLab 3.2 allows to disable notebook-wide history tracking (see issue 10791 nad PR 10949), but with a caveat: when moving cells you may loose the undo history, which is why the setting is marked as experimental (it requires more work to be exposed or enabled by a default). To get the selective undo/redo please add:

{
    "experimentalDisableDocumentWideUndoRedo": true
}

in Advanced Settings EditorNotebook, save, and reload JupyterLab (if you use it in a browser a refresh should suffice).

You can also stick with JupyterLab 3.0 if this is a deal breaker. To downgrade you can use pip:

pip install "jupyterlab<3.1"

or conda:

conda install -c conda-forge "jupyterlab<3.1"

but I would recommend sticking with JupyterLab 3.2 and trying out the new setting so you can contribute to the discussion (if you experience any problems or believe it could be improved).

like image 154
krassowski Avatar answered Oct 13 '22 05:10

krassowski