Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python Shift + enter not working in VScode with jupyter

I have a new install of VS Code Version 1.50.1 with the python extension that now added the Jupyter extension. The Jupyter extension build number is 2020.12.411183115 When I press shift enter on the default it adds a new line below. You can see in the video that shift + enter should work to run the line. At this point the only way I can run code in the interactive window is with ctrl + shift + p and select run selected cell.

Edit after working with Danny Varod and the comments below:
Changing the keyboard shortcut to ctrl + enter and nothing happens (it does not add a new line below). I press ctrl + shift + p and I see that the correct shortcut is crtl + enter but it will not trigger the action

enter image description here

Here is a screenshot of my keyboard shortcuts before the change.

enter image description here

Changing my keyboard shortcuts to match the comment below. Now when I press ctrl + enter nothing happens.

enter image description here

like image 256
Jeffkrop Avatar asked Dec 10 '20 19:12

Jeffkrop


People also ask

How do you move cells in Jupyter Notebook VS Code?

The selected code cell can be changed using the mouse, the up/down arrow keys on the keyboard, and the J (down) and K (up) keys. To use the keyboard, the cell must be in command mode.

How do you open a remote Jupyter Notebook in VS Code?

Press Control+Option+Cmd+n to create a new file, then select Jupyter Notebook.


3 Answers

In settings.json under .vscode add the following line:

"jupyter.sendSelectionToInteractiveWindow": true

Then Shift+Enter should work.

like image 152
Igor Micev Avatar answered Sep 20 '22 06:09

Igor Micev


Please use the following shortcut key settings:

{ "key": "shift+enter",           "command": "jupyter.execSelectionInteractive", "when": "editorTextFocus"
},

This shortcut key is set with the use conditions, and it can be used only when it is confirmed (including the control panel is opened). Therefore, we can remove the use conditions for this shortcut key.

enter image description here

like image 22
Jill Cheng Avatar answered Sep 19 '22 06:09

Jill Cheng


Shift+Enter also inserted a new line for me, unmapping this prevented this.

I changed to mappings to:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

These mappings work for me, however, in Jupyter notebooks (.ipynb) the Ctrl+Enter and Shift+Enter are swapped vs. what I defined 🤔.

Also, I am using the following Python extensions:

  • "MagicPython" magicstack.magicpython
  • "Jupyter" ms-toolsai.jupyter

Both installed by:

  • "Python Extension Pack" donjayamanne.python-extension-pack

When I open .ipynb files they open as Jupyter notebooks. When I open .py files I can either use Jupyter or MagicPython (and nether say Python).

enter image description here

enter image description here

like image 42
Danny Varod Avatar answered Sep 19 '22 06:09

Danny Varod