Skip to content
Related Articles

Related Articles

Setting up Sublime Text for C++ Competitive Programming Environment
  • Difficulty Level : Expert
  • Last Updated : 29 Apr, 2021

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<inputf.in>outputf.out"],
    "shell":true,
    "working_dir":"$file_path",
    "selector":"source.cpp"
}

The above block of code is used for taking input from the file “inputf.in” 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.
  • inputf.in: 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++ -std = c++17 stdc++.h

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live and Geeks Classes Live USA

My Personal Notes arrow_drop_up
Recommended Articles
Page :