VSCode Setup for Competitive Programming

VSCode Setup for Competitive Programming
3 min read
Posted by

Note

  • Programming Languages Covered: C, C++, Java, Python
  • Code Editor: Visual Studio Code (VSCode)
  • Compatible Operating Systems: Windows, Linux, macOS

Installing Programming Languages

If you're solving problems on platforms like CodeChef, Codeforces, or Spoj, you may be using online compilers. However, this can be cumbersome due to the need to constantly switch tabs to copy and modify test cases. Programming in your own IDE offers numerous advantages, such as IntelliSense for code completion and no latency issues.

Additionally, online compilers like Ideone may expose your code publicly, potentially leading to plagiarism. To avoid these issues, setting up your local environment is highly recommended.

Python 3 Installation

For Windows, installing Python is straightforward. Download the installer from the official Python website and run it. Ensure you check the "Add Python to PATH" option during installation.

GCC Setup for C and C++

GCC is the standard compiler for C and C++. For Linux, GCC can be easily installed through your package manager. For Windows, you can use MinGW, which provides GCC builds.

Steps to Install MinGW:

package view

package view

  1. Download MinGW.
  2. After installation, open the MinGW package manager.
  3. Mark all the packages with a green tick for installation.
  4. Click on the “Installation” menu and select “Apply Changes.”
  5. Wait for the installation to complete.

Adding GCC to Environment Variables:

windows environment variables

windows environment variables

mingw environment variables setup

mingw environment variables setup

  1. Open the environment variables settings by searching for it in the Start menu.
  2. Add the following paths:
    • C:\MinGW\bin
    • C:\MinGW\mingw32\bin
    • C:\MinGW\lib\gcc

Java Setup

  1. Download the latest JDK from Oracle's official site.
  2. Install the appropriate installer for your system (e.g., x64 Installer for Windows, ARM64 DMG Installer for macOS).
  3. Add Java to your environment variables by adding the path:
    C:\Program Files\Java\jdk-20\bin

Installing VSCode

Visual Studio Code (VSCode) is a versatile tool for competitive programming. It provides a customizable environment for coding in multiple languages like C++, Python, and more. Download VSCode from here.

Installing Essential Extensions

Start by installing the following key extensions:

Setting Up Code Runner for the Terminal

  1. Install the Code Runner extension and restart VSCode.
  2. Open VSCode settings with Ctrl + ,
  3. Search for "Code-runner: Run In Terminal" and enable it, or add "code-runner.runInTerminal": true in settings.json

Optional Configuration

If you want to remove .exe and .class files after execution, follow these steps:

  1. Press F1 or Ctrl + Shift + P to open "Preferences: Open User Settings (JSON)."
  2. Add the following under "code-runner.executorMap":
json
json
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt && rm $fileNameWithoutExt.class",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt && rm $fileNameWithoutExt.exe",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt && rm $fileNameWithoutExt.exe"

Running Code in VSCode

To run a file (C, C++, Java, or Python), press Ctrl + Shift + N. For macOS, the shortcuts are similar, use ⌘ Command + Shift + N.

For Linux, the same shortcut Ctrl + Shift + N is typically used.

With this setup, your competitive programming experience will be smoother and more efficient, allowing you to focus on solving problems rather than wrestling with your tools.