Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run the select code in VScode?

I want to run the select code of python in VScode. Till now, I have to copy the code and paste it in the terminal below to run. The system is mac OS. So is there any way to run the code directly after I selected the code? For example, like the shortcuts. Thanks.

like image 319
yanachen Avatar asked Aug 15 '16 08:08

yanachen


3 Answers

@yanachen, this is now possible in VS Code. All you need to do is:
1. Ensure python is running in the VS Code terminal window
2. Select the text you wish to execute in python
3. Invoke the command 'workbench.action.terminal.runSelectedText' as defined in the following link: https://code.visualstudio.com/docs/editor/integrated-terminal#_key-bindings

like image 39
Don Avatar answered Nov 06 '22 04:11

Don


There is no default keybindings for command "Run Selected Text in Active Terminal", but you can create one.

  • Press Ctrl+K, Ctrl+S to open File → Preferences → Keyboard Shortcuts.
  • Search for workbench.action.terminal.runSelectedText in keybindings.
  • Press the icon on the left to open a windnow with this message "Press desired key combination..." and make your choice. (I've pressed Ctrl+Alt+R - as this combination was not used yet.)
  • Press Enter to store your keybinding.

Tested on VSCode 1.30.2 on Windows 10 Pro.

like image 90
Piotr Avatar answered Nov 06 '22 04:11

Piotr


Now it's supported by default shortcut "shift" + "enter".

  1. select the proper code snippet
  2. press "shift" + "enter"
like image 7
BinhuiLiu Avatar answered Nov 06 '22 03:11

BinhuiLiu