How to Set Up Sublime Text for Competitive Programming in Windows and Linux

A guide to setting up Sublime Text for programming (in Java, C/C++, and Python) in Windows and Linux.

G Ajeet
4 min readNov 9, 2021
Photo by AltumCode on Unsplash

Sublime Text is a very lightweight text editor with nice syntax and color highlighting for many different languages.

But why a text editor?

Using an IDE for competitive programming is just overkill. An IDE can be CPU and memory expensive, besides it is tedious to create a project again and again, and not to mention these days many modern IDE won’t even work smoothly on older computers but that won’t be stopping us from doing competitive programming!

This article will provide a solution for compiling and executing your source code directly through a terminal/command prompt as well as a convenient interface for managing test cases and output for competitive programming. After configuration it will look like this:

Let’s Begin Setting Up the Sublime Text

Now I will be assuming that you’ve already installed the compilers and added them to the path as well as downloaded and installed the Sublime Text.

First, go to my GitHub repository for downloading the config files here. Click on Code then Download Zip.

Go to the directory where it has been downloaded and extract it.

Setups for Windows

Open the extracted folder and copy the Packages folder to the directory mentioned below and replace all existing files if need be.

C:\Users\<username>\AppData\Roaming\Sublime Text\

Note: Replace the <username> with your username on your machine. AppData is a hidden folder, take a look here if you don’t know how to unhide the folders in Windows.

Setups for Linux

Open the extracted folder, go to Packages you’ll see three folders for each programming language. Open each folder one by one and edit the files with the extension (sublime-build) then find and replace xfce4-terminal with your preferred terminal application name, for example, if you’re using Ubuntu or any distribution with Gnome desktop environment then replace it with gnome-terminal.

Now you may copy the Packages folder to the directory mentioned below

/home/<username>/.config/sublime-text/

Note: Replace the <username> with your username on your machine. The folder .config is a hidden folder. Just press CTRL + H while being in a file manager to see the hidden folders.

Setting up the Interface for Competitive Programming

Open up the Sublime Text editor and on the menu bar go to:

View -> Layout -> Columns: 3

Then, go to:

View -> Layout -> Max Columns: 2

Now you should have something looking like this:

Now on the menu bar go to:

File -> Open Folder..

and select a folder for your competitive programming files. In that folder create two files input.txt and output.txt and open each of them up in the two stacked layouts we just created in Sublime Text.

Important Note: The source code files you create and save must be in the same directory with the input.txt and output.txt files to take input from input.txt and show the result on output.txt otherwise, you’ll get the error “input.txt : No Such file or directory” .

Ways to Compile and Run Your Program

Now that you have followed and taken care of the things mentioned above, you should now be able to compile and run your Java, C/C++, and Python programs in two different ways.

For testing purposes, write up a simple program in your preferred language that takes a name as a string input and prints out Hello, <yourname>.

Executing Your Program in Terminal/Command Prompt

To compile and run the program press CTRL + SHIFT + B and select the build system. The one with not written CP, in the end, cannot be exact here as they may differ for different languages. This will open up your terminal in which you can type input and see the output on the go, solving the issue of running interactive programs in Sublime Text.

Executing Your Program for Competitive Programming

To compile and run the program press CTRL + SHIFT + B and select the build system, the one with CP in the end, cannot be exact here as they may differ for different languages. This will take input written in input.txt and dump out the result in output.txt .

Sublime will remember your most recently used build system, so you don’t have to press CTRL + SHIFT + B and select the build system every time, instead of only when you switch between build systems, so you can just press CTRL+B which will run the last used build system.

Let me know if you face any issues or errors.

That’s it Happy Coding!😃

--

--