Competitive Programming(CP) Environment Setup using Sublime Text.
Time is of paramount importance while participating in Competitive Programming contests where we don’t just need to be accurate but also efficient in the solutions we generate and where we wouldn’t want our tools to bottleneck our speed and thinking processes.
This is where Sublime Text comes to the rescue. Sublime Text is a free-to-use sophisticated text editor for coding, which has a smooth user interface and amazing performance.
So let’s dive in with the setup.
Before we start, Make sure you have MinGW installed in your system and added to your System Path.
Open Command Prompt and type in the following command to check if you have MinGW installed.
gcc — version
If MinGW isn’t installed, click here to see the steps to set up MinGW for windows.
Step 1: DOWNLOAD AND INSTALL
Sublime Text is available for Mac, Linux, and Windows. Follow the link below to download and install Sublime Text on your PC. Once downloaded, run the installation file and open Sublime Text
https://www.sublimetext.com/download
Step 2: 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 using the steps below.
- Open Sublime Text and goto Tools > Build Build System > New Build System
#build sys
2. Paste the following code and save the file as “compile.sublime-build”
{
“cmd”: [“g++.exe”,”-std=c++17", “${file}”, “-o”, “${file_base_name}.exe”, “&&” , “${file_base_name}.exe<inputf.in>outputf.in”],
“shell”:true,
“working_dir”:”$file_path”,
“selector”:”source.cpp”
}
This block of code is used for taking input from the file “inputf.in” and printing the output to “outputf.in”.
Step 3: Window layout setup
Having three Separate tabs opened and switching between them during contests is counterintuitive, and it only slows us down, instead, we would want a layout where we could code and see the output in the same window and change inputs easily for purposes of testing.
Follow the steps below to set up your window layout:
- First, create three new files named file.cpp , inputf.in and outputf.in and make sure that the three files are in the same folder.
- Open the three files created and click on View>layout>Columns :3, This will create three columns.
- Next click on View > Groups >Max Columns:2 , adjust the file.cpp window to your comfort and voila! you are ready to code.
Let’s test our setup .
Paste the following code in the file.cpp window
#include <bits/stdc++.h>
using namespace std ;
int main() {
int n ;
cin >> n ;
cout <<”hi the number is “ << n <<endl ;
}
Enter the number 3 in input.in window
and then press ctrl + b , to build the code
Make sure that the newly built build system named as compile is selected
Do check out Algozenith demo courses to start learning about the basics of Programming.