Skip to content
Advertisement

How to run all cells without moving to the end (Jupyter Lab)

When I use Shift + Enter, Jupyter Lab moves my screen down to the next cell. If I click Run -> Run all cells, it moves me to the bottom of my script. Do you know how to disable this screen movement?

It is very annoying and time-consuming as I have to scroll my script back in an attempt to find my last edited line.

Advertisement

Answer

You’ll want to take advantage of one of the nice features in JupyterLab, the ability to open a new view. See number ‘2. Side by Side’ listed in 5 Hidden Features in JupyterLab You Should Start Using . Or watch the video under ‘Create multiple synchronized views of a single notebook’ at the JupyterLab ‘Notebooks’ documentation page.

The specific steps suggested in your case so that you won’t need to scroll back to your last edited line:

  1. Right-click on the notebook’s named tab in your main panel and select from the list of options ‘New View for Notebook‘. By default it will put the new view on the side but optionally you can click and hold on the named tab of the new view and drag it around to arrange it in the main view panel wherever you like. For example, maybe you prefer the option of having the two views stacked vertically.

  2. In both views, bring your long cell into focus. Pick one of the views to be the one you’ll use to run and the other to be the one you edit in. (If you went with keeping them side-by-side, pick the right side view to be where you edit, maybe?)

  3. Click in the one you’ll use to run cells and run the cell like normal. In that view you’ll get dragged to the bottom of the code cell; however, the other view will remain anchored in place where you left it.

  4. You can switch over to that anchored view (suggested right-side in this example) to further edit your code and then click in the bottom of the cell in the other view pane, the one you selected as your “Run” location (left-side in this suggested approach), and type shift-enter to run again.

  5. Rinse and repeat for a better experience with no more clunky scrolling.


This post outlined the approach I’ve suggested as well, calling it having ‘one “editing” window and one “interacting” window’.


Related aside: I wish the 5th item listed in 5 Hidden Features in JupyterLab You Should Start Using would get updated to not use an exclamation point with pip as the example. The %pip and %conda magics were added and are the best way to go now for using pip or conda inside a notebook.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement