vscode配置文件中的变量替换,例如${workspaceFolder}

摘要

vscode配置文件中的变量替换,例如${workspaceFolder}


预定义的变量

vscode中预定义了许多变量,当你在配置config时可以使用这些变量。例如,你想设置include目录为当前文件夹,你可以将${workspaceFolder}添加到include路径中,这样当你打开任何工程,vscode都会从该工程目录下查找include的文件。

  • ${workspaceFolder} - the path of the folder opened in VS Code
  • ${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
  • ${file} - the current opened file
  • ${relativeFile} - the current opened file relative to workspaceFolder
  • ${relativeFileDirname} - the current opened file’s dirname relative to workspaceFolder
  • ${fileBasename} - the current opened file’s basename
  • ${fileBasenameNoExtension} - the current opened file’s basename with no file extension
  • ${fileDirname} - the current opened file’s dirname
  • ${fileExtname} - the current opened file’s extension
  • ${cwd} - the task runner’s current working directory on startup
  • ${lineNumber} - the current selected line number in the active file
  • ${selectedText} - the current selected text in the active file
  • ${execPath} - the path to the running VS Code executable
  • ${defaultBuildTask} - the name of the default build task

相关/参考链接

Variables Reference

要在VS Code配置SDL,您需要按照以下步骤操作: 1. 安装MinGW:首先,您需要安装MinGW来编译C/C++代码。您可以从MinGW的官方网站下载安装程序,并按照提示进行安装。 2. 安装SDL2库:您可以从SDL2的官方网站下载SDL2开发库。解压缩下载的文件,并将SDL2文件夹放在您喜欢的位置。 3. 配置环境变量:在系统环境变量添加MinGW和SDL2的路径。找到MinGW的安装路径,并将其添加到系统的Path变量。同样,找到SDL2库的路径,并将其添加到系统的Path变量。 4. 创建VS Code项目:在您的项目文件夹创建一个新的文件夹,并使用VS Code打开它。 5. 创建C/C++配置文件:在您的项目文件夹创建一个名为`.vscode`的文件夹,并在该文件夹创建一个名为`c_cpp_properties.json`的文件。 6. 配置C/C++属性:打开`c_cpp_properties.json`文件,并添加以下内容: ```json { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:/SDL2/include" // 替换为您的SDL2头文件路径 ], "defines": [], "compilerPath": "C:/MinGW/bin/gcc.exe", // 替换为您的MinGW编译器路径 "cStandard": "c11", "cppStandard": "gnu++14", "intelliSenseMode": "gcc-x64" } ], "version": 4 } ``` 请确保替换路径为您在步骤2和步骤3安装和配置的实际路径。 7. 创建任务配置文件:在`.vscode`文件夹创建一个名为`tasks.json`的文件。 8. 配置任务属性:打开`tasks.json`文件,并添加以下内容: ```json { "version": "2.0.0", "tasks": [ { "type": "shell", "label": "build", "command": "gcc", "args": ["-g", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe", "${file}"], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [] } ] } ``` 9. 编译和运行:现在,您可以在VS Code编写和保存您的SDL代码文件,并使用快捷键`Ctrl+Shift+B`来编译和运行您的程序。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值