Use "IPython for VSCode" plugin.
Install it and then use Send Select Text (or current line) To IPython
If you want use shortcut setting with original shift+enter to execute command above, Use One of below methods.
Shortcut setting - Normal
open shortcut setting: Macos it's cmd+k cmd+s.
search command above and right click to modify the keyboard binding as shift+enter.
Next, right click again to modify the When expression as:
editorTextFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'
Right click and select show same key bindings
Find command Python: Run Selection/Line in Python Terminal and Right click to disable it.
Shortcut setting - JSON
Open shortcut setting and click Upper right corner to open JSON config
Append these settings:
{
"key": "shift+enter",
"command": "ipython.sendSelectedToIPython",
"when": "editorTextFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "shift+enter",
"command": "-python.execSelectionInTerminal",
"when": "editorTextFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
}
code runnerextension as well. - winklerrr