How to Run Code in VS Code

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

How to Run Code in VS Code

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

The Shortcut to Run Code in VS Code

In VS Code, you only need to use a shortcut to run your code. That shortcut is Ctrl + Alt + N. There are a few more ways to run code.

Pressing F1 and then choosing Run Code also works. If you want to type it out after pressing F1, you’re free to do that as well.

Users can right-click the text editor and then select Run Code in the context menu. With only two clicks, your code will run.

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

Should you want to stop your code from running, the shortcut is Ctrl + Alt + M. Pressing F1 also lets you choose the Stop Code Run option. This option is also available in the editor title menu and Output Channel.

Lastly, you can right-click on the Output Channel to open the context menu and select Stop Code Run.

Learning these shortcuts and methods should make running and stopping code a little easier in various situations.

How to Run C Code in VS Code

Besides knowing C code and VS Code, you’ll have to download the C/C++ extension. Without it, you won’t be able to run C code within VS Code.

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

Setting Up the Required Software

  1. Launch VS Code.
  2. Find the C/C++ extension on the extensions marketplace.
  3. Install the extension.
  4. Download and install MinGW.
  5. Make sure you 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 Path.
  10. Select Edit.
  11. From here, click on New.
  12. Paste the MinGW path and click the OK button.
  13. Click OK for the other popup windows.

Coding in VS Code

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

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

How to Run Python Code in VS Code

Running Python code in VS Code is relatively easy. You’ll need an extension and a Python interpreter. The former is found in the VS Code extensions marketplace, but Python interpreters vary depending on how they’re installed.

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

With the preliminaries out of the way, let’s get into 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 at the top-right corner of your editor.

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

How to Run JS Code in VS Code

JavaScript works even better in VS Code due to the latter already having JavaScript IntelliSense, refactoring, and additional advanced features for the language. Since VS Code works so well with JS Code, there’s little preliminary configuring needed to start working right away.

Here’s how you’ll run JavaScript code in VS Code:

  1. Download and install NodeJS on your PC.
  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 navigate to 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 only included these as placeholder names.

A more straightforward way to run JavaScript code also exists:

  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 show your code.

If you only want to test a few lines of code and then save it, this method shines. You can finish within 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 for debugging or launching code files, and VS Code is entirely compatible with these types of codes and debugging. In this section, you’ll learn how to run code with arguments.

Before you do so, you have 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 running code with arguments:

  1. Open launch.json and add your arguments.

  2. Select the file to debug.
  3. 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.

Coding Made Easy

With this knowledge, running code in VS Code should become as natural as breathing – with enough practice. The various languages you can use with VS Code make it a powerful and straightforward IDE to pick up. As such, many developers highly recommend aspiring programmers learn how to use it.

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

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.

Todays Highlights
How to See Google Search History
how to download photos from google photos