VS code : 设置编译运行快捷键
VS code中没有编译运行的快捷按键,只能通过编写 tasks.json 实现。
一开始用的 launch.json 里的 (windows) launch 配置,设置调试开始前执行一个 task 任务,task 任务设置好 gcc 编译语句(或者 mingw32-make),后来发现个严重问题,这么做的话执行编译好的程序是在 VS code的内置调试控制台里的,然而内置调试控制台是不能输入数据的!!?
通过设置 "externalConsole": true 虽说可以通过弹出外部终端解决这个问题,但是弹出外部终端总是会卡一下,弹出个窗口也不好看。。2333
于是,如果不需要 gdb 调试程序,需要直接编译运行程序的话,写个编译+运行的 task 不就可以啦。
由于VS code 中的 task 一个任务只能写一个指令(只能填写一个 “command”),不过。。。在args里通过加分号就可以写很多条指令了。。。
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"label": "COMPILER AND RUN","type": "shell","command": "gcc","args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe",";","./${fileBasenameNoExtension}.exe"],/*"command": "mingw32-make","args": ["all",";","./${fileBasenameNoExtension}.exe"],*/"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared","showReuseMessage": false,"clear": true},"problemMatcher": {"owner": "GCC COMPILER","fileLocation": ["relative","${workspaceRoot}"],"pattern": {"regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$","file": 1,"location": 2,"severity": 3,"message": 4}},"group": {"kind": "build","isDefault": true}},{"label": "COMPILER","type": "shell","command": "gcc","args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"],/*"command": "mingw32-make","args": ["all"],*/"presentation": {"echo": true,"reveal": "always","focus": false,"panel": "shared","showReuseMessage": false,"clear": true},"problemMatcher": {"owner": "GCC COMPILER","fileLocation": ["relative","${workspaceRoot}"],"pattern": {"regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$","file": 1,"location": 2,"severity": 3,"message": 4}},"group": {"kind": "build","isDefault": true}}]
}
上面的 "COMPILER AND RUN" 任务用来编译+运行。下面的 "COMPILER" 可以用来给 gdb launch 调试前运行,只编译不运行。这样就可以快捷方便的在 VS code 内部集成终端上编译并运行了,可以正常输入,速度还很快~
按默认快捷键 CTRL + SHIFT + B 弹出可运行的任务列表,选中敲回车立即编译运行~ ~ ,多个文件编译可以改写 tasks 里的编译指令,也可以改成 mingw32-make 然后写 Makefile 。
END
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
