Edit / Go to Line

I wanted to assign a keyboard shortcut for “Edit/Go to Line”, but it doesn’t work – the menu item in the UI is inactive, both in cell and body editor. Toggling the line numbers doesn’t help. Tried in different notebooks. Jlab 4.4.3 py3.9

Your post is short on details and I’m not following…
Let’s start with the menu item before you even try to add a keyboard shortcut. Does selecting it from the menu work?
By ‘inactive’ do you mean grayed out and unselectable? If the menu item is disabled like that, you are probably not in the right context. Context is very important in modern JupyterLab and Juptyer Notebook.
I’m going to use JupyterLab that should be more pristine / standard to discuss this. (I suggest you try here, too, in case you have tried things and possibly messed things up.) If you go to here and click on the ‘launch binder’ badge you will spin up a Jupyter session from a remote machine in your browser, provided via the MyBinder service. Currently, this gives JupyterLab 4.4.3.
After that opens, if I choose to open a new and type in some code on a few lines, then I can go to the ‘Edit’ menu and select at the bottom ‘Go to Line…’. And then I get a form area along the bottom where I can enter what line to go to. Does that work for you?

After trying that a few times, make sure it is closed. We are going to discuss adding a keyboard shortcut for this next. Let’s make sure what we want to use doesn’t do anything. If I am in the body of the Python code editor and I type ALT + g (that is the ALT key with a g at same time) then I get in my Chrome browser on My Mac, the ‘copyright’ symbol added. Do you get that, too? For the sake of discussion here it’s okay if you don’t see the same thing, as long as the ‘Go to Line’ prompt doesn’t open.

However, next I am going to add a custom keyboard shortcut so that I can trigger that with the very key combination I just tried.

I go to ‘Settings’ along the menu ribbon and then from the menu drop-down that comes up, I choose ‘Settings Editor’ from the bottom.

That brings up the ‘Settings’ tab. From there, I select ‘Keyboard Shortcuts’ in the listing on the right side of that window.

When the Keyboard Shortcuts listing comes up if I enter ‘line’ in the search bar, I see several involved in that but ‘Go to Line’ isn’t one of them. So now we want to edit things to add one. In the upper right corner, I click on ‘JSON Settings Editor’ and then I again select ‘Keyboard Shortcuts’ from the listing on the left side. On the left side of the pane that comes up that is labeled ‘System Defaults’, about 25 lines down you should see ‘// List of commands followed by keyboard shortcuts:’. (And above there are the steps you do to customize shortcuts.) So I can search in there with the text ‘line’ and find an option of fileeditor:go-to-line that is commented out.
So I’ll use that information to add a shortcut in the ‘User Preferences’ panel on the right.
(Note that the disabled ‘disk’ icon in the upper right along the top of the ‘User Preferences’, too.)

I copied the code below and made that the entire contents of the ‘User Preferences’ pane on the right:

{
  shortcuts: [
    {
      command: 'fileeditor:go-to-line',
      selector: 'body',
      keys: [
        'Alt G',
      ],
    },
  ],
}

(Above based on here and searching line in the Settings listing.)

Now you should see a formerly disabled ‘disk’ icon in the upper right along the top of the ‘User Preferences’ become enabled. Click it to save the settings. (Interestingly, if you had an error in the JSON it will disable the ‘disk’ icon and give you an indication along the bottom. You can test this by adding a random curly brace after a comma on the 9th line and it should indicate along the bottom of the pane [syntax error] JSON5: invalid character ‘}’ at 9:7. Just delete the added bracket and it will indicate again ‘No errors found’ along the bottom of the ‘User Preferences’ pane.

Next I tested this change by clicking back to my editing script tab and hitting Alt + g and this time the ‘Go to line’ prompt box opened at the bottom and I could enter a line to go to.
Are you able to do that in a launched session?
Are you then able to do some of these things in your JupyterLab and have them work?

I should add that ‘Alt + g’ was just chosen as an example that I got working with the described steps, feel free to edit as you choose.

Hey, it looks like “Go to Line” only works for opening various files in Jupyter, but not the notebook cells. Tried it on Binder. I should probably raise a feature request

Yes, I noted in earlier versions of JupyterLab, v3.6.3, Alt+G opens a different-looking prompt at the top of cells and it works. Even though the Edit menu has no such enabling of the ‘Go to Line..’ listing there. Meaning the context doesn’t seem to react to offer it from the Edit menu for some reason. I thought in one of the earlier version four options, in v4.0.9 it opens the same style prompt (as the document editing now) at the bottom of cells even though the context menu doesn’t offer it, but I was unable to type in the prompt and get it to go to a line. Current versions don’t offer it at all from that former shortcut which I think is meant to correspond to the context menu setting leaving it disabled at present.

I cannot speak to the reasoning behind these choices regarding cells.