Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Setting up Sublime Text for C++ Competitive Programming Environment

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Note: The following steps assume a Windows OS environment.

Sublime Text is a text editor for coding. It has a smooth user interface and other exciting features. During the live contest, it is always favorable to compile the program in a local IDE instead of an online IDE’s.

In this article, we will discuss how to set up a Sublime Text Editor for Competitive Programming in C++ how to create our own build system in the sublime text editor.

Install Sublime Text Editor:

Download the setup file of Sublime Text from here and then install it.

Install MinGW Compiler:

MinGW is a native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications.

  • Download the MinGW file from here.
  • Install all the Basic Setup of MinGW.
  • Mark all the packages for installation.
  • Click on the Apply Changes option under the Installation tab as shown below:

Setting up the Environment

After completing the above steps, GCC is up and running. Now, the Environment Variable’s Path is to be updated. Follow the below steps for the same:  

  • Go to My Computer, then Right Click to get Properties > Advanced System Settings > Environment Variables.

  • Now under the System Variables Tab, look for Path > Click on Path > Click on Edit > Click on New.

  • Now locate the bin folder inside the MinGW installation folder in the C drive.
  • Copy the path of the bin folder. By default, the path is: C:\MinGW\bin
  • Paste this new path in the list and click OK.

Now Sublime Text is able to access g++ from its terminal as the path variable has been updated.

Creating a Build System

Sublime Text provides build systems to allow users to run external programs. Create a new build system for Sublime Text for setting up C++ compilation. 

  • Open Sublime Text editor and then go to Tools > Build System > New Build System.
  • Paste the following code in the file and save it.
  • Name the file as “CP.sublime-build“.
    "cmd": ["g++.exe", "-std=c++17", "${file}",
            "-o", "${file_base_name}.exe",
            "&&", "${file_base_name}.exe<>outputf.out"],

The above block of code is used for taking input from the file “” and prints the output to “outputf.out”.

Setting up the Window Layout

Create three new files as shown below and make sure all of them are in the same folder.

  • file.cpp: The file for writing the code.
  • The file where we will be giving the input.
  • outputf.out: The file where the output will be displayed.

Now, perform the following steps:

  • Select View > Layout > Columns : 3. This will create three columns in the workspace. Move the three files into three columns.
  • Select View > Groups > Max Columns : 2.
  • Select the build system we just created from Tools > Build System > CP.

Below is the image to illustrate the same:

Ready for executing the programs:

Precompile Headers:

The compilation time can speed up by precompiling all the header files i.e., by precompiling the bits/stdc++.h header file. Perform the following steps for doing so:

  • Navigate to the stdc++.h file. By default, this file is located at: “C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits”
  • Open the Power shell or the command window on the current folder. For this right-click while pressing the Shift key.
  • Run the below command to compile the header.

g++ stdc++.h -std=c++17

My Personal Notes arrow_drop_up
Last Updated : 01 Feb, 2022
Like Article
Save Article
Similar Reads
Related Tutorials