Command Runner 透彻指南(VSCode)
Command Runner 透彻指南(VSCode)
垃圾code-runner
使用g++编译
-
在 VSCode 中安装 Command Runner 插件
-
将 VSCode 的默认终端设为 PowerShell
-
在 VSCode 设置里的 settings.json 中把下面的代码加进去就行了(环境变量中没有g++就换成绝对路径)。
"command-runner.terminal.autoFocus": true,
"command-runner.commands": {
"compile-cpp": "cls; cd '${fileDirname}'; echo 'Compiling...'; g++ -g -std=c++14 -O2 '-Wl,--stack=2147483647' '${fileBasenameNoExtension}.cpp' -o '${fileBasenameNoExtension}.exe'; $lastcompile = $?; if($lastcompile) { echo 'Compilation Completed!'; } else { echo 'Compilataion error!'; } echo `n; ",
"run-cpp": "cls; cd '${fileDirname}'; if($lastcompile) { echo 'The program is running!'; echo '----------------------------------'; $start = Get-Date; .\\'${fileBasenameNoExtension}.exe'; $end = Get-Date; $success = $LastExitCode; echo `n----------------------------------; $cost = ($end-$start).TotalSeconds; echo \"Process exited after $cost seconds with return value $LastExitCode\"; } else { echo 'Source file is not compiled.'; } echo `n; ",
"compile&run-cpp": "cls; cd '${fileDirname}'; echo 'Compiling...'; g++ -g -std=c++14 -O2 '-Wl,--stack=2147483647' '${fileBasenameNoExtension}.cpp' -o '${fileBasenameNoExtension}.exe'; $lastcompile = $?; if($lastcompile) { echo 'Compilation Completed!'; echo `n'The program is running!'; echo '----------------------------------'; $start = Get-Date; .\\'${fileBasenameNoExtension}.exe'; $end = Get-Date; $success = $LastExitCode; echo `n----------------------------------; $cost = ($end-$start).TotalSeconds; echo \"Process exited after $cost seconds with return value $LastExitCode\"; } else { echo 'Compilataion error!'; } echo `n; "
}, -
在 VSCode 快捷键绑定里的 keybindings.json 中把下面代码加进去就行了
{
"key": "F9",
"command": "command-runner.run",
"args": {
"command": "compile-cpp",
"terminal": "runCommand"
}
},
{
"key": "F10",
"command": "command-runner.run",
"args": {
"command": "run-cpp",
"terminal": "runCommand"
}
},
{
"key": "F11",
"command": "command-runner.run",
"args": {
"command": "compile&run-cpp",
"terminal": "runCommand"
}
}
这些设置会给你搞上这些操作: (老DEVC++了)
F9 编译当前程序
F10 运行当前程序
F11 编译并运行
我按c++14,O2编译的,如果想改的话请改 "compile-cpp"
和 "compile&run-cpp"
里编译器g++的参数
自定义指令
在settings.json中:
"command-runner.commands" :{ |
在keybindings.json中:
//一组快捷键 |
评论