How to run code in VS Code

Who I am
Matthew M. White
@matthewmwhite
Author and references

One of the most popular source code editors, Visual Studio Code, commonly known as VS Code, is very beginner-friendly. Its user-friendly interface and advanced features make it a favorite of beginners and seasoned programmers alike.

If you're new to VS Code and looking for a simplified guide to running code, you've come to the right place. We'll walk you through setting up the required software and running the code using familiar languages ​​like C/C++ and Python, as well as running command-line arguments.



The shortcut to run code in VS Code

In VS Code, you just need to use a shortcut to run your code. This shortcut is Ctrl+Alt+N. There are a few other ways to run code.

Pressing F1 and then choosing "Run Code" also works. If you want to type it after pressing F1, you are also free to do so.

Users can right-click on the text editor and then select "Run Code" from the context menu. In just two clicks, your code will run.

“Run code” is also an option in the editor title menu and the file explorer context menu.

If you want to stop your code execution, the shortcut is Ctrl + Alt + M. Pressing F1 also lets you choose the “Stop Code Execution” option. This option is also available in the editor title menu and the output channel.

Finally, you can right-click on the output channel to open the context menu and select "Stop Code Execution".


Learning these shortcuts and methods should make it easier to run and stop the code in various situations.

How to Run C Code in VS Code

In addition to knowing C code and VS code, you will need to download the C/C++ extension. Without it, you won't be able to run C code in VS Code.


Here are the instructions for running C code in VS Code:

Software Requirements

  1. Launch VS Code.
  2. Find the C/C++ extension on the extension marketplace.
  3. Install the extension.
  4. Download and install MinGW.
  5. Make sure to install the "Mingw32-base package" and "Ming32-gcc-g++ package" options.
  6. Copy the path to the “bin” folder in MinGW.
  7. Go to Windows advanced system settings.
  8. Select “Environment Variables”.
  9. In the “System Variables” section, click on “Path”.
  10. Select "Edit".
  11. Choose a new path.
  12. Paste the MinGW path and click the "OK" button.
  13. Click "OK" for other pop-ups.

Coding in VS Code

  1. Create a folder for your C code.
  2. Add Folder to VS Code.
  3. Hover your mouse over the C code folder and click the “+” button.
  4. Write the file name.
  5. Start coding in C.
  6. Run the code with Ctrl+Alt+N or any of the other methods mentioned above.

Once the one-time software setup is complete, you will be able to easily use VS Code and the C language. Just make sure that other required programs are properly installed before running the code, especially the packages.



How to run Python code in VS Code

Running Python code in VS Code is relatively easy. You will need a Python extension and interpreter. The first is found in the VS Code extension market, but Python interpreters vary depending on how they are installed.

Before installing the others, you should already have Python on your PC. Checking it beforehand is also essential.

With the preliminaries done, let's move on to the coding process.

  1. With a command prompt, create an empty folder and open it.
  2. Open VS Code in the new empty folder.
  3. Choose the Python interpreter for VS Code to use.
  4. Create a Python source file.
  5. Start coding in Python.
  6. Run the Python code by clicking the "Play" button in the upper right corner of your editor.

The interpreter you install depends on your needs, but VS Code works incredibly well with Python regardless of your choice of interpreter.


How to run JS code in VS Code

JavaScript works even better in VS Code because VS Code already has JavaScript IntelliSense, refactoring, and additional advanced features for the language. Since VS Code works so well with JS Code, there's little preliminary setup needed to start working right away.

Here's how to run JavaScript code in VS Code:

  1. Download and install NodeJS on your computer.
  2. Launch VS Code and create a new folder.
  3. Write in JS and name the file with the .js extension.
  4. Save the changes.
  5. Open a VS Code terminal.
  6. Type “cd yourdirectoryname” to access the JavaScript code.
  7. If you want to check your code output, type "node yourfilename" and wait.

Your directory and files will be named differently, so we've only included them as placeholder names.


There is also an easier way to run JavaScript code:

  1. Install Code Runner.
  2. Write or open a JavaScript code file.
  3. Run the code with Ctrl+Alt+N or any other method.
  4. The output window will display your code.

If you only want to test a few lines of code and then save it, this method shines. You can finish in a minute and have a file ready to store for future use.

How to run code with arguments in VS Code

Command line arguments are intended for debugging or launching code files, and VS Code is fully compatible with these types of code and debugging. In this section, you will learn how to run code with arguments.

Before doing so, you need to get “launch.json”. If you don't have it, you can create it by following these steps:

  1. Go to “Run”.
  2. Select "Add configuration".

The following steps are for executing code with arguments:

  1. Open launch.json.
  2. Add your arguments.
  3. Select the file to debug.
  4. Click "Run and Debug" to debug your code.

These are the basics of running your code with arguments. In this case, we're talking about Python since it's the simplest example.

Simplified coding

With this knowledge, running code in VS Code should become as natural as breathing – given enough practice. The different languages ​​you can use with VS Code make it a powerful and easy to learn IDE. As such, many developers urge budding programmers to learn how to use it.

Do you like using VS Code? What do you think of the interface? Let us know your thoughts in the comments section below.

Audio Video How to run code in VS Code
add a comment of How to run code in VS Code
Comment sent successfully! We will review it in the next few hours.