This guide is deprecated. New content at docs.sublimetext.info
Build systems run external programs to process your project’s files and print captured output to the output panel. Ultimately, they call subprocess.Popen.
Build systems use JSON. Here’s an example build system:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Array containing the command to run and its desired arguments.
Note
Under Windows, GUIs are supressed.
The file_regex option uses a Perl-style regular expression to capture up to four fields of error information from the build program’s output, namely: file name, line number, column number and error message. Use groups in the pattern to capture this information. The file name field and the line number field are required.
When error information is captured, you can navigate to error instances in your project’s files with F4 and Shift+F4. If available, the captured error message will be displayed in the status bar.
windows, osx and linux are additional options which override any build system options for the corresponding platform only. Here’s an example:
{
"cmd": ["ant"],
"file_regex": "^ *\\[javac\\] (.+):([0-9]+):() (.*)$",
"working_dir": "${project_path:${folder}}",
"selector": "source.java",
"windows":
{
"cmd": ["ant.bat"]
}
}
In this case, ant.bat will be executed under Windows, while for the other platforms ant will be used instead.
$file | The full path to the current file, e. g., C:\Files\Chapter1.txt. |
$file_path | The directory of the current file, e. g., C:\Files. |
$file_name | The name portion of the current file, e. g., Chapter1.txt. |
$file_extension | The extension portion of the current file, e. g., txt. |
$file_base_name | The name only portion of the current file, e. g., Document. |
$packages | The full path to the Packages folder. |
$project | The full path to the current project file. |
$project_path | The directory of the current project file. |
$project_name | The name portion of the current project file. |
$project_extension | The extension portion of the current project file. |
$project_base_name | The name only portion of the current project file. |
Snippet style formatting can be used with these variables, for example:
${project_name:Default}
This will emit the name of the current project if there is one, otherwise Default.
${file/\.php/\.txt/}
This will emit the full path of the current file, replacing .php with .txt.
Select Tools | Build in the Sublime Text menu or press F7.
External programs used in build systems need to be in your PATH. As a quick test, you can try to run them from the command line first and see whether they work. However, note that your shell’s PATH variable might differ to that seen by Sublime Text due to your shell’s profile. Also, note that you can use the path option in a .build-system to specify additional directories to PATH.
See also