Previously, according to the online method in the Sunlime text 2 configuration of C/C + + development environment, but each time in the menu to switch to a different compilation configuration, and I feel very troublesome, tossing the next, their personal preferences on the configuration file made a few changes, the final result is as follows:
Shortcut key Description:
Run:
The result is displayed in the bottom text bar: Ctrl +,
The results are displayed in the cmd window: Ctrl +.
C:
Compile: Ctrl + Shift + B
Compile and run (show results in the bottom text bar): Ctrl + Shift +,
Compile and run (display the results in a CMD window): Ctrl + Shift +.
C++:
Compiling: Ctrl + B
Compile and run (show results in the bottom text bar): Ctrl + Alt +,
Compile and run (display the results in a CMD window): Ctrl + Alt +.
Compile the configuration file: Menu-to-Tools-build system--New build system ...
If the ConverToUTF8 plugin is not installed, follow the instructions in the note to modify it (line 6th)
Mingw64-11.sublime-build:
{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "-Wall", "-std=c++11"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"encoding": "GBK", //If you haven`t install ConvertToUTF8, please install it or delete/comment this line or use "encoding": "utf-8",
"shell": true,
"variants":
[
{
//Shortcut: Ctrl+Shift+B
"name": "Run", //Build C
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}", "-Wall", "-std=c11"]
},
{
//Shortcut: Ctrl+,
"name": "RunLocal", //Run in bottom text box
"cmd": ["${file_path}/${file_base_name}"]
},
{
//Shortcut: Ctrl+.
"name": "RunCmd", //Run in cmd window
"cmd": [ "start", "CMD", "/C", "${file_path}/${file_base_name} & pause"]
},
{
////Shortcut: Ctrl+Shift+,
"name": "BuildCAndRunLocal", //Build C & run in bottom text box
"cmd": ["CMD", "/C", "gcc ${file} -o ${file_path}/${file_base_name} -Wall -std=c11 & ${file_path}/${file_base_name}.exe"]
},
{
//Shortcut: Ctrl+Shift+.
"name": "BuildCAndRunCmd", //Build C & run in cmd window
"cmd": ["start", "CMD", "/C", "@echo off & gcc ${file} -o ${file_path}/${file_base_name} -Wall -std=c11 & @echo on & ${file_path}/${file_base_name}.exe & pause"]
},
{
//Shortcut: Ctrl+Alt+,
"name": "BuildCppAndRunLocal", //Build C++ & run in bottom text box
"cmd": ["CMD", "/C", "g++ ${file} -o ${file_path}/${file_base_name} -Wall -std=c++11 & ${file_path}/${file_base_name}.exe"]
},
{
//Shortcut: Ctrl+Alt+.
"name": "BuildCppAndRunCmd", //Build C++ & run in cmd window
"cmd": ["start", "CMD", "/C", "@echo off & g++ ${file} -o ${file_path}/${file_base_name} -Wall -std=c++11 & @echo on & ${file_path}/${file_base_name}.exe & pause"]
}
]
}
Shortcut profile: Menu--Preferences key Bindings-user
Default (Windows). Sublime-keymap:
[
{ "keys": ["ctrl+0"], "command": "build", "args": {"variant": "BuildC" } },
{ "keys": ["ctrl+,"], "command": "build", "args": {"variant": "RunLocal" } },
{ "keys": ["ctrl+."], "command": "build", "args": {"variant": "RunCmd" } },
{ "keys": ["ctrl+shift+,"], "command": "build", "args": {"variant": "BuildCAndRunLocal" } },
{ "keys": ["ctrl+shift+."], "command": "build", "args": {"variant": "BuildCAndRunCmd" } },
{ "keys": ["ctrl+alt+,"], "command": "build", "args": {"variant": "BuildCppAndRunLocal" } },
{ "keys": ["ctrl+alt+."], "command": "build", "args": {"variant": "BuildCppAndRunCmd" } }
]
Sublime Text 2-based MinGW-C + + configuration file