Image Credit : Unsplash

Vs Code Setup for Running Program Directly

Suvash Kumar
3 min readSep 9, 2020

I usually use Jetbrein’s product for development work as a project. But it is not efficient to use those IDEs for a small project or single file. Because those IDEs are very heavy and bit slow. For this, I need to think for else. I can solve this problem using VS Code. As I need to install a compiler/interpreter, a small setup can provide me this.

Prerequisite

  • Basic knowledge of this language you want to use. Because this post is not about language syntax.
  • VS Code editor.
  • Compiler/interpreter for this language.
  • Code Runner extension for VS Code.
  • Internet connection. (Just for installation)

VS Code and Compiler/interpreter installation

At first install VS Code and compiler/interpreter. You can take help from Google. Make sure that path of the compiler/interpreter has been set to the system. Open your terminal and check the version of this compiler/interpreter. If you are able to see the version then path setup is done successfully.

Code Runner Installation

Code Runner is a VS Code extension which allows running code snippet or file written in various language.

C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Visual Basic .NET, Clojure, Haxe, Objective-C, Rust, Racket, AutoHotkey, AutoIt, Kotlin, Dart, Free Pascal, Haskell, Nim, D, Lisp, Kit, and custom command.

You can download Code Runner from this link or by searching in VS Code extension tab.

Code Runner in Extensions tab

After installation, restart VS Code.

Now Test This Setup

Open or create a file in VS Code and write some code for testing. Example, for C++,

#includes<iostream>
using namespace std;
int main()
{
cout << "I am running inside VS Code";
}

There are four way to run a code:

  • Right-click in mouse and select Run Code.
  • Use shortcut Ctrl+Alt+N.
  • Press F1 and select Run Code.
  • Press triangle (run button) from the toolbar.

After running a code you see the output in the output tab. But there is a problem. The output tab is by default read-only. You cannot give input in it. So a program with user input can not run successfully in the output tab.

#include<bits/stdc++.h>
using namespace std;
int main()
{
string name;
cout << "Enter your name : ";
cin >> name;
cout << "Hello, Mr. " << name;
}
Output tab in VS Code

But we can solve this problem if we can run the program in the terminal tab. Oh, there is a tip! If you want to stop a program before terminate then use shortcut Ctrl+Alt+M.

Run Program in Terminal Tab

For this go to File > Preference > Setting > Extension. Then click to Run Code Configuration. After scrolling, you found a checkbox named Run in Terminal. Check this box.

Or you can do it by going to setting.json file and adding this code :

"code-runner.runInTerminal": true

From now program run in the terminal tab. And you able to run the program in VS Code directly.

To read this article in Bangla visit this link:ডিরেক্টলি কোড রান করার জন্য VS Code সেটআপ

--

--