68

There's an option in Jupyter Notebooks where you can select some cells, and then hit F, which opens up a Find & Replace feature.

This shortcut doesn't work in Jupyter Lab. It's not in the Commands list and it's not in the Edit Menu (there is only Find -- and Find Next and Find Previous). Nor can I find a global (not specific to a cell selection) Find & Replace feature.

Does this feature exist? I've found old mentions of it on the internet -- has it been removed? I'm using Jupyter Lab version 1.2.3.

Denziloe
  • 7,473
  • 3
  • 24
  • 34

3 Answers3

123

The Find & Replace feature was not removed, but the way it is named in the menu (simply Find...) and the UI which requires the user to click on a small arrow to access it may be confusing. Please see the GIF below which demonstrates how to use the search & replace feature:

enter image description here

If you need a slightly more powerful refactoring tool (i.e. distinguishing the variable scopes) you may want to check out my jupyterlab-lsp project which now includes support for the rename action (see here for a demonstration GIF, but please install a newer version, not the tag linked).

krassowski
  • 13,598
  • 4
  • 60
  • 92
  • 9
    Got it, thank you! I can use Jupyter Lab again. This is pretty bad UI in my opinion, I think most users will miss this. Changing the toggle from an arrow to a "replace" icon, or just having replace toggled on by default, would be much better. – Denziloe Jan 13 '20 at 14:36
  • 2
    Actually you can also press "Ctrl+F" to enable the process above. – Jeremy May 27 '20 at 12:34
  • @krassowski Is it possible to switch between search modes, e.g. regex mode, text mode and escape character mode? – Hoeze Feb 05 '21 at 23:55
  • I think the `.*` button toggles regular expression. – krassowski Feb 06 '21 at 00:14
  • Is it possible to limit the scope of replace to just the selected cell? – linello Mar 26 '21 at 12:59
  • 1
    @linello there is an ongoing work to make it possible: https://github.com/jupyterlab/jupyterlab/pull/10067 – krassowski Apr 18 '21 at 10:57
  • 7
    "Confusing"? How about "virtually invisible"? – Emy May 06 '21 at 13:34
  • 1
    Please help JupyterLab devs improve the situation by chiming in [this thread](https://github.com/jupyterlab/jupyterlab/issues/6650) discussing usability of find-and-replace function. Please give thumbs up to solutions that you like, and suggest new solutions (but please avoid comments like "me too" to keep the discussion easier to read). – krassowski May 07 '21 at 12:04
  • 1
    This doesn't work for me at all. When I go to the edit menu, the find... selection is always grayed out. If I am just in the cell, or highlight some code, or choose a whole cell or choose all the cells in the notebook, it is always grayed out. – Gerry Harp Sep 09 '21 at 19:36
  • @GerryHarp please open an issue on GitHub if you want an assistance with this one. – krassowski Sep 09 '21 at 19:54
2

I am not sure if the original question was answered correctly. If I were to find and replace in only a selected cell, the top rated solution doesn't seem to work (in JupyterLab). The desired result is obtained by clicking on the ... button in the F&R menu. Check the attached snippet.enter image description here

1

It can be easily done using keyboard in Jupyter as well.

Step 1: If you are inside any code block/cell, press Esc.

Step 2: Press F

Gif for illustration