Build Systems in Sublime Text 3
Sublime has highly customizable build systems that can add to your productivity if you learn how to use them to your advantage. You can define one for your project and whenever you are editing any file, you can run certain commands on the source file and see the output in the sublime console, without leaving the editor.
I mostly use IntelliJ for development but still find myself switching to sublime text time to time, depending upon the nature of the project. I mainly use sublime when I have to write some small script or a library, and when I use it I prefer to setup the build system to make it easier to test. In this post I am going to explain how to create one by creating an example build system for a hello-world php application. But the steps should be same for any language. So let’s get started.
The first thing that you are going to do is create a new build system. You can do that by going to below path
Tools > Build System > New Build System
This will open a new file named
untitiled.sublime-build. Update the file and put the below content
"cmd": ["php", "$file"],
Now save this file with the name
php.sublime-build. To give you some details about the file content;
cmdhere means the command that we need to run with the arguments that we want to pass it
selectoris an optional string used to locate the best builder to use for the current file scope. This is only relevant if
Tools > Build System > Automaticis true
file_regexspecifies the file pattern that our build is going to be working with.
After saving the file you can see the build system inside
Tools > Build System. Now you can run any php file ending with
php as specified above in the above snippet. Now let’s test our build system. Create a new php file and put the below content in it
echo “Hello world”;
Now let’s run this file that we have created. So select
Tools > Build Systems and hit
CMD + B if you are on Mac,
CTRL + B if you are on windows or Linux. Once you run it, you will notice the output for the build in the console, as shown in the image below
In case you want to cancel a stuck build, you can do that by pressing
CTRL + Cif you are on Mac, or
Ctrl + Breakif you are on windows or linux.
"cmd": ["node", "$file"],
Hope you enjoyed the article, you can learn more about the build systems in the Sublime Docs, if you have any comments or feedback, leave them down below and feel free to connect with me on twitter or say hi via email.