Python Forum
Is there any keyboard shortcut to run code from Visual Studio Code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there any keyboard shortcut to run code from Visual Studio Code?
#1
I know you can right click in the editor and select Run Python File in Terminal.
Or I can right click the name of the python file from left panel and select Run Python File in Terminal.

But what i am trying to find is if there is a keyboard shortcut to run the code?

My bad. I was missing code runner extension and so was unable to see the Run triangle symbol at the top of code editor.
Once I installed Code Runner, I can see the Run Code symbol (triangle) and om highlighting it, I see the shortcut Ctrl + Alt + N
Reply
#2
I have installed Visual Studio Code and added extensions - Python, Code Runner.
With Code Runner, now I can see the Run Code symbol (triangle) and on highlighting it, I see the shortcut Ctrl + Alt + N
But when I try to use it to run the code that asks for user input, I can't find a way to provide the input.
When I try to enter user input, I get error message "Cannot edit in read-only editor"
I think this is because I am missing some configuration part for Code Runner like setting up PATH or some other Workspace settings.

Please assist me in identifying what all configuration will I need to do and how?
[UPDATE]: I did select "Add Python 3.6 to PATH" while installing Python.
I have attached screenshots for reference.
   
   

Note: Even now when I right click and select "Run Python File in Terminal" for the same program, I can enter user input fine and get the expected output.
   
Reply
#3
Install Code Runner,get a button and shortcut Ctrl+Alt+N.
Can also build own task that run Python.
Reply
#4
Finally I got answer to my second question (which I wanted to post as a new question) from SO.

Answer:
You can provide input by telling code runner to use the terminal.
To do this, there is a setting called code-runner.runInTerminal, set to false by default, that you can set to true.
In the lower left hand corner of the screen on "VS code" you'll see the icon which will take you to settings when clicked.

Thank you to the helper who answered it there.
I wanted to post that answer here so if someone like me comes here searching for the same thing, he/she will find help here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Autocompletion for Python in Visual Studio user3481 1 2,183 Dec-10-2020, 12:03 PM
Last Post: snippsat
  Installing the Visual Studio Code on Linux - how to do that!? apollo 4 3,262 Oct-05-2019, 09:48 PM
Last Post: apollo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020