Sublime Text 3 2021 Setup for Competitive Programming

The final Sublime Text 3 setup for the people that are diligently devoted to competitive programming using C++ and Python

Sublime Text 3 Editor

During a programming contest on sites like CodeForces, Codechef, or Google Kickstart and many more, our main goal is to be as quick and efficient as possible with our logic and coding.

There is a saying by Abraham Lincoln, “Give me six hours to chop down a tree, and I will spend the first four sharpening my axe.”

But in today’s technological world despite having a lot of editors and spending six hours or more, still some editors become sometimes clunky, non-intuitive and impede our speed right at the moment of submission of our powerful solutions .

But not from now.

Let’s Create the scene 👁

Setting up the Environment

Downloading and installing Sublime Text 3 is pretty straightforward.

Just click on the link below to download and install Sublime Text 3,

Create a folder named, CPSubmission or whatever name you want and place it in the appropriate location on your system. Now every files related to CP will be stored as this will make our environment systematic for competitive programming.

Make sure you are in your folder (in this case, CPSubmission)…

Now create four files namely …

  1. main.cpp — For C++ users

2. — For Python users

3. input.txt — To write our input directly in this file and our code will read the input from this.

4. output.txt — Output will be generated in this file.

Now, Open Sublime and click on View << Sidebar << Show Sidebar to show the side bar so as to manage files easily.

Now make sure input.txt, output.txt and anyone of (main.cpp or are opened in tabs,

III. C++ Environment

MinGW is a native Windows port of the GNU Compiler Collection (GCC) and is required to run C/C++ files.

Install and setup the latest MinGW Compiler from the link below …

Now we don’t need to include different headers for our data structures and algorithms and can speed up compilation time by precompiling all the header files from one single file infamously named as bits/stdc++.h header file.

To setup this file, navigate to C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++\mingw32\ and create a folder named bits. In this folder, create a file named stdc++.h and copy-paste the following code from here.

3. Snippets

Snippets are the best and fastest way to automatically include the basic code that we want to write everytime in our c++ file.

To create c++ snippet,

In Sublime, Tools << Developers << New Snippet and clear the contens of the file and copy-paste the following code and save the file.

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1000000007;
double eps = 1e-12;
#define ln "\n"
#define printVector(a) for(int i=0; i<a.size(); i++){cout<<a[i]<<" ";}cout<<ln;
#define print_array(a,n) for(int i=0; i<n; i++){cout<<a[i]<<" ";}cout<<ln;
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define take_vector(a) for(auto &x:a)cin>>x;
#define take_array(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define take_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cin>>a[i][j];}}
#define print_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cout<<a[i][j]<<" ";}cout<<ln;}
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/gcd(a,b))*b
#define count(a,x) count(a.begin(), a.end(),x)
#define sum(a) accumulate(a.begin(), a.end(),0)
#define max_ele(a) *max_element(a.begin(), a.end())
#define min_ele(a) *min_element(a.begin(), a.end())
void solve()
// Here I am, Beautiful
int main()
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll t = 1;
cin >> t;
for (int it = 1; it <= t; it++)
//cout << "Case #" << it+1 << ": ";
return 0;
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->

Restart Sublime, go to main.cpp file and start typing basicpp and hit enter,

Now you main.cpp file should resembles the below

Note — Before start coding, make sure to take a look at the snippets so as to understand the macros and how to use them.

4. AutoCompletion

Autocompletion while writing the code undoubtedly increases the speed of coding.

One of the best autocompletion for C++ out there is EasyClangComplete.

You can check it out here …

To install this plugin,

In Sublime, Tools << Command Palette then type install package and hit enter and then search for EasyClangComplete,

Your screen should resembles the following …

Hit Enter and it will be installed.

But before using it we need to install Clang.

To do this, click the link below to setup Clang…

To check if is installed correctly, open your terminal and type,

clang --version

Your screen should resembles the following…

Voila!!! 🥳

5. Auto Formatting

We programmers are the Artists and whatever we create tends to be a masterpiece.

What Autoformatting does is to make your code look systematic and beautiful by adding appropriate spacing and line break.

One of the best auto formatting plugin for C++ in Sublime is SublimeAStyleFormatter.

To install, in Sublime, Tools << Command Palette and type install package and then type SublimeAStyleFormatter and it will be installed in a moment.

Now to use this plugin,

Restart Sublime, got to Preferences << Package Settings << SublimeAStyleFormatter << Settings — User and add the following code and save the file…

"autoformat_on_save": true

Restart Sublime and see the magic of SublimeAStyleFormatter in your c++ file.

6. AutoSave

Now most of time we forget to save our file which often leads to chaos.

But not now, Sublime has the option to auto save file whenever you lose focus from the file.

To enable autosave in Sublime, go to Preferences << Settting and add the following lines of code …

"save_on_focus_lost": true

Save the file, restart Sublime and it will do the magic now.

Voila 🥳. We have done our C++ setup

IV. Python Enviroment

Well everything is already done with the setup, we just need to add snippet and some plugin to use python for competitive programming.

1. Snippet

Open Sublime, go to Tools << Developers << New Snippet and add the following code and save the file.

import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
sys.setrecursionlimit(100000000)inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lambda: map(float,input().strip().split())
seq =lambda: list(map(int,input().strip().split()))
ceil =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1
flush =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr =lambda x: stdout.write(str(x))
import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
# main code goes here]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->

Now, in file type basicpy and hit enter and it will add the snippet to the file

Your screen should resembles the following …

2. AutoCompletion

The best Auto Completion in Python is provided by Anaconda and it is pretty straightforward to install this…

Open Sublime, go to Tools << Command Palette and type install package and hit enter, then type Anaconda and hit enter to install Anaconda.

Restart Sublime and your Auto Completion is successfully activated.

3. Auto Formatter

One of the best Auto Formatter for Python is AutoPEP 8 which uses the PEP 8 style formatting for Python

To install it , open Sublime and go to Tools << Command Palette and type install package and hit enter, then type AutoPEP 8 and hit enter to install Anaconda.

After installation, restart Sublime and go to Preferences << Package Settings << AutoPEP8 << Setting-User and add the following code …

"format_on_save": true

This will enable the auto formatting the python file when it is saved.

Voila 🥳

V-2030 — Prodigious Reader. Love Competitive Programming, Creating Things, Machine Learning, Mathematics, Economics, Web Dev