扩展
visual studio keymap
快捷键
- Open the Command Palette.
- View > Command Palette… (Ctrl+Shift+P)
- See an overview of the user interface.
- Help: User Interface Overview in the Command Palette.
- Install support for your favorite programming language from the Extensions view.
- View > Extensions (Ctrl+Shift+X)
- Change your keyboard shortcuts and easily migrate from other editors using keymap extensions.
- File > Preferences > Migrate Keyboard Shortcuts from…
- Code > Preferences > Migrate Keyboard Shortcuts from… on macOS
- Open the Keyboard Shortcuts editor.
- File > Preferences > Keyboard Shortcuts (Ctrl+K Ctrl+S)
- Code > Preferences > Keyboard Shortcuts on macOS
- Printable keyboard cheat sheet.
- Help > Keyboard Shortcuts Reference (Ctrl+K Ctrl+R)
- Customize your editor with color themes.
- File > Preferences > Color Theme (Ctrl+K Ctrl+T)
- Code > Preferences > Color Theme on macOS
- Show all commands.
- Help > Show All Commands (Ctrl+Shift+P)
- Explore VS Code features in the Interactive Editor Playground.
文件组织
.vscode folder#
Workspace specific files are in a .vscode folder at the root. For example, tasks.json for the Task Runner and launch.json for the debugger.
Platform-specific properties
In the example below, debugging the program always stops on entry except on macOS:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulpfile.js",
"stopOnEntry": true,
"osx": {
"stopOnEntry": false
}
}
]
}
编译调试顺序
-
launch.json 用来调试 -
task.json 用来生成,相当于是任务的集合,可通过ctrl+shift+p ,运行任务,比如: {
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/g++"
}
]
}
参考VS Code 运行C++程序以及TASKS.JSON和LAUNCH.JSON文件的基础配置
The task’s properties have the following semantic:
-
label: The task’s label used in the user interface. -
type: The task’s type. For a custom task, this can either be shell or process . If shell is specified, the command is interpreted as a shell command (for example: bash, cmd, or PowerShell). If process is specified, the command is interpreted as a process to execute. -
command: The actual command to execute. -
windows: Any Windows specific properties. Will be used instead of the default properties when the command is executed on the Windows operating system. -
group: Defines to which group the task belongs. In the example, it belongs to the test group. Tasks that belong to the test group can be executed by running Run Test Task from the Command Palette. -
presentation: Defines how the task output is handled in the user interface. In this example, the Integrated Terminal showing the output is always revealed and a new terminal is created on every task run. -
options: Override the defaults for cwd (current working directory), env (environment variables), or shell (default shell). Options can be set per task but also globally or per platform. Environment variables configured here can only be referenced from within your task script or process and will not be resolved if they are part of your args, command, or other task attributes. -
runOptions: Defines when and how a task is run. -
c_cpp_properties.json 用来配置C++标准
可参考:
vscode-docs/launch-json-reference.md at main · microsoft/vscode-docs · GitHub
或网页Configure launch.json for C/C++ debugging in Visual Studio Code
以及Get Started with C++ on Linux in Visual Studio Code
VScode tasks.json和launch.json的设置
注意:
要保证launch.json中preLaunchTask 的值与此文件中label 的值相同
插件
Tips
调试
- 如果应用程序在sudo环境下和普通用户环境下表现不一致并且当前调试需要管理员模式,在Ubuntu下一种可能的做法是:
- 设置配置文件(makefiletool自动生成,stopAtEntry需要自己加,敲“”后会出现提示):
{
"makefile.extensionOutputFolder": "./.vscode",
"makefile.launchConfigurations": [
{
"cwd": "/home/qemu/bin/debug",
"binaryPath": "/home/qemu/bin/debug/hello",
"binaryArgs": [],
"stopAtEntry": true,
}
]
}
- 运行或调试之后在终端(vscode的终端)输入sudo su,之后重新调试或运行
评论区找到的2,感谢!
参考
|