You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sublime Text 3:如何为C#编译与运行设置快捷键绑定?

How to Set Custom Keybindings for C# Compile and Run in Sublime Text 3

Hey there! I totally get the hassle of clicking through "Build With" twice every time you want to test your C# code—let's fix that with custom keyboard shortcuts so you can code faster without all the extra clicks. Here's how to do it:

Step 1: Open the User Keybindings File

First, launch your custom keybindings editor:

  • On Windows/Linux: Press Ctrl+Shift+P, type Key Bindings: User, and hit Enter.
  • On Mac: Press Cmd+Shift+P, type Key Bindings: User, and hit Enter.
    Or navigate via the menu: Preferences > Key Bindings—you’ll see a split view, with default bindings on the left and your custom editable pane on the right. We’ll work in the right pane.

Step 2: Add Your Custom Keybindings

Paste the following valid JSON into the right pane (make sure there are no trailing commas if it’s the last entry!). You can adjust the key combinations to whatever you prefer—I used F6/F7/F5 as intuitive examples:

// Compile C# code (matches the "CSharp" build option)
{
    "keys": ["f6"],
    "command": "build",
    "args": {"build_system": "Packages/C#/CSharp.sublime-build"}
},
// Run compiled C# program (matches the "CSharp - Run" build option)
{
    "keys": ["f7"],
    "command": "build",
    "args": {"build_system": "Packages/C#/CSharp.sublime-build", "variant": "Run"}
},
// Optional: One-key compile + run (skips both "Build With" clicks entirely)
{
    "keys": ["f5"],
    "command": "build",
    "args": {"build_system": "Packages/C#/CSharp.sublime-build", "variant": "Run", "build_on_save": false}
}

Quick Explanation of Each Part:

  • "keys": The keyboard shortcut you want to use—feel free to swap f6, f7, f5 for something else like ctrl+shift+b (just avoid conflicting with existing Sublime shortcuts!).
  • "build_system": Points to the default C# build system file included with Sublime’s C# package. If you’re using a custom C# build setup, update this path to match your file’s location.
  • "variant": "Run": Targets the "Run" variant defined in the default C# build system, which executes the compiled executable right after building.

Step 3: Save and Test

Save the keybindings file (Ctrl+S on Windows/Linux, Cmd+S on Mac), then open your C# code file to test:

  • Hit F6 to compile your code—check the output panel for any errors.
  • Hit F7 to run the compiled program.
  • Or hit F5 to do both actions in one go!

If something doesn’t work, double-check the build system path: go to Preferences > Browse Packages > C# and confirm the CSharp.sublime-build file exists there.

内容的提问来源于stack exchange,提问作者Non Player Character

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:36:08