Reputation: 1
I just started coding yesterday and I'm currently studying C#. I am using Sublime Text 3 as it is my favorite Code Editor. But I have a problem when compiling the C# file. When I am compiling, I always have to click the "Build With" and then Choose the "CSharp" and then click the "Build With" again and choose the "CSharp -Run" to see the changes in my codes. So what I want to know is how can i set a Key Bind for "CSharp" and "CSharp -Run"? Thank you in advance for someone who will answer my question.
Here's my Default Keymap:
{ "keys": ["f7"], "command": "build" },
{ "keys": ["ctrl+b"], "command": "build" },
{ "keys": ["ctrl+shift+b"], "command": "build", "args": {"select": true} },
{ "keys": ["ctrl+break"], "command": "cancel_build" }
And here's my the Default Keymap -user:
[
{ "keys": ["ctrl+r"], "command": "build", "args": {"select": true} },
]
And also this is my C# build-system:
{
"cmd": ["cmd", "/c", "del", "${file/\\.cs/\\.exe/}", "2>NUL", "&&", "csc", "/nologo", "/out:${file/\\.cs/\\.exe/}", "$file"],
"file_regex": "^(...*?)[(]([0-9]*),([0-9]*)[)]",
"variants": [
{
"name": "Run",
"cmd": ["cmd", "/c", "start", "cmd", "/c", "${file/\\.cs/\\.exe/}"]
}
],
}
Photo of my Sublime Text 3 with my said problem above
Photo of my Key Bind for "Build With"
Upvotes: 0
Views: 1146
Reputation: 22821
The short version of the answer to your question is that you're not providing the correct argument to the build
command, so what you've done is duplicate an existing key binding on another key; you want to pass the variant
argument instead to tell Sublime directly to run the build with the variant you want to execute.
The longer version is that the build
command takes two arguments, select
and variant
.
The select
argument tells Sublime that before it runs the build, if there is more than one applicable build for the current file (for example there is more than one build system or there are variants that apply), it should ask you for the build first. This is the same as the Ctrl+Shift+B keyboard shortcut or the Tools > Build With...
menu entry.
What you want instead is the variant
argument; that tells Sublime that it should carry out the build using the last build system that was used, but it should explicitly use the variant
that you provided.
For the case of your build system, your key binding would look like this:
{
"keys": ["ctrl+r"],
"command": "build", "args": {
"variant": "Run"
},
},
The value of the variant
argument has to exactly match the name
key in the variants
section of your build system (i.e. case is important). If you get it wrong, instead of building nothing will happen and you'll see a message appear in the status line like No Build System with variant whatever
.
Note that this key binding blocks the default key binding for Goto Symbol
, should you want to use that functionality while you're working. The command is still available in the menu at View > Goto Symbol
however.
Upvotes: 4