Hello everyone! I’ve been watching some tutorials on youtube about sublime and then i’ve tried to work with it too. I have one question.
Is there a way to build a specific file using a specific key from my keyboard? I work on something where i have 1 main file, then 5 secondary. So, when i press the F5 key I want to build only that one main file after i am editing something in a secondary file. I hate switching between pages.
I use PAWN.
Specific keybinding for building specific file
I am gonna try to figure it out right now. The fact that I’ve just downloaded sublime text 2 hours ago doesn’t help me too much. My build system looks like this:
{
“cmd”: [“pawncc.exe”, “$file”, “-o$file_path/$file_base_name”, “-;+”, “-v2”, “-d3”, “-Z+”, “-\)+”],
“path”: “S:/External/pawno”,
}
It builds my file, but only when i am on the main page. If i am on a secondary it builds the secondary, which is bad, because i don’t need to build that.
Sorry for taking your time and thank you so much for trying to help me!
Is the name of the file you want to build always the same no matter what or is it something that’s specific to your project?
The name of the file i want to build will be the same forever, i dont need to change it. And it relates to my project, the other 5 secondary files are linked to the main one… I am still searching, but i am like a duck swimming in oil. I’m stuck…
If you’ve just downloaded ST 2 hours ago, you may also be interested to know that switching files is super fast with Ctrl+P (Cmd+P on Mac) and typing a little bit of the file name (or its capital or “kebob” letters).
An example of a key binding for executing a command to compile a specific file would look something like this (untested) example:
{
"keys": ["f5"], "command": "exec",
"args": {
"shell_cmd": "pawncc PutFilenameHere -oPutOutputameHere -;+ -v2 -d3 -Z+ -\\)+",
"env": {"PATH": "$PATH;S:/External/pawno"}
},
},
The exec
command is what build systems use to execute things, so if you know that you need to execute an external tool to perform an exact action, you can invoke it directly as seen here. Most of the fields that appear in a sublime-build
file are passed to this command directly to carry out the build.
Note that you don’t have access to the various variables like $file
and such in this case, so if the file is always the same name but its location depends on the current project, you need to use a build system instead.
However that said, note that in a build $file
expands to the name of the current file; if you want it to always build the same file, you can just put the name there directly.
Similarly a build can contain more than one variant
to allow you to select from multiple potential builds, allowing you to build different things. You can also set up key bindings to execute a variant of the current build.
The following playlist covers build systems in Sublime; this includes an item on variant
builds:
Thank you for your answers! I am now trying to apply them in my case. I am following mister Odat Nurd tutorials and your CTRL + P shortcut saves me some clicks. Thank you, i will try until i will succeed…
LATER EDIT: WORKING!!! I’ve watched 2 tutorials then i went back to this:
However that said, note that in a build
$file
expands to the name of the current file; if you want it to always build the same file, you can just put the name there directly.
I have replaced the $file with the direct link to my file from the directory. It is working now, it doesn’t matter if I am in another page, it will still compile the main one! Thank you once again!
(i am so happy, finally)