Setting up Sublime Text for C++ Competitive Programming Environment
Sublime Text is an IDE popular among competitive programmers due to its smooth and simple user interface, customizable plugins and other exciting features.
In this article, we will discuss how to set up Sublime Text for competitive programming in C++.
Table of Content
Overview
Sublime Text does not have an inbuilt terminal window, so the programmers generally create an input and an output buffer file manually and keep it open side-by-side to provide input and see the output of the programs written. One such example is given in the below image.

Our objective is to create a similar UI layout that should be able to take input from the file and show output to another file.
Prerequisite
For setting up sublime text for C++ competitive programming, we need to have followed stuff in our environment:
- There should be a working C++ compiler in the system like MinGW compiler. Refer to this article to know How to Install the MinGW Compiler.
- There should also the Sublime text present in the system. Refer this article to know How to Install Sublime Text.
Now we can start setting up Sublime Text for CP using C++.
Step 1: Creating a Build System
Sublime Text provides build systems to allow users to run external program. We will create a new build system for C++ program compilation using the steps given below:
- STEP 1: Open Sublime Text editor and then go to Tools > Build System > New Build System.

- STEP 2: Paste the following code in the file and save it with name "CP.sublime-build". Remember NOT TO CHANGE THE SAVE DIRECTORY.
{
"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".
- STEP 3: Go back to the build system and you will find the CP as one of the builds. Select it as default build system.

Now, we will be able to execute the C++ code. Let's move on to setting up the layout.
Step 2: Setting up the Window Layout
According to the layout shown above, a minimum of three files should be opened at the same time. So, create three new files with the given name and make sure all of them are in the same folder.
- source.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.
Follow the below steps to arrange the files is better order.
- STEP 1: Select View > Layout > Columns : 3. This will create three columns in the workspace. Open the three files into three columns.

- STEP 2: Select View > Groups > Max Columns: 2. This group of two columns together and one will be left.

The Sublime Text is ready to use now. But we can also perform one extra step to make the execution of the programs even faster.
Step 3: Precompile Headers (Only for GCC)
The compilation time of C++ programs can speed up by precompiling all the header files i.e. by precompiling the <bits/stdc++.h> header file (as it contains all the standard header files of C++). Perform the following steps for doing so:
- STEP 1: Navigate to the stdc++.h file. By MinGW, this file is located at: "C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits"
- STEP 2: Open the Power shell or the command window on the current folder. For this right-click while pressing the Shift key.
- STEP 3: Run the below command to compile the header.
g++ stdc++.h -std=c++17

Step 4: Create Custom Code Snippet
We can speed up our coding by creating custom code snippets in Sublime Text. This allows us to easily insert frequently used template or boilerplate code for C++ problems saving a lot of time during competitive programming contests.
Follow bellow steps:
- STEP 1: Select > Tool > Developer > New Snippet...

- STEP 2: Write the code for your snippet with whatever you want to include. For example, below is the basic C++ snippet for CP:
#include<bits/stdc++.h>
using namespace std;
void solve(){
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// int t; cin >> t; while(t--)
solve();
return 0;
}
- STEP 3: Now, replace "Hello, ${1:this} is a ${2:snippet}" with your custom code snippet and save the file as snippetname.sublime-snippet in the default snippets directory.

- Step4: When you're working in a .cpp file, type cpp and press Tab. The full C++ template will be automatically inserted into your file.