vscode 替换变量

变量替换

Visual Studio Code在调试和任务配置文件以及某些选择设置中支持变量替换。使用$ {variableName}语法在launch.json和task.json文件的键和值字符串内部支持变量替换。

预定义变量

  • ${workspaceFolder} - 在VS Code中打开的文件夹的路径
  • ${workspaceFolderBasename} - VS Code中打开的文件夹名称,不带任何斜杠(/)
  • ${file} - 当前打开的文件
  • ${relativeFile} - 当前打开的相对于workspaceFolder的文件
  • ${relativeFileDirname} - 当前打开文件的目录名(相对于workspaceFolder)
  • ${fileBasename} - 当前打开的文件的基本名称
  • ${fileBasenameNoExtension} - 当前打开的文件基本名称,不带文件扩展名
  • ${fileDirname} - 当前打开的文件的目录名
  • ${fileExtname} - 当前打开文件的扩展名
  • ${cwd} - 启动时任务运行程序的当前工作目录
  • ${lineNumber} - 活动文件中当前选择的行号
  • ${selectedText} - 活动文件中当前选定的文本
  • ${execPath} - VS Code可执行文件的路径
  • ${defaultBuildTask} - 默认构建任务的名称

例如:

Supposing that you have the following requirements:

  1. A file located at /home/your-username/your-project/folder/file.ext opened in your editor;
  2. The directory /home/your-username/your-project opened as your root workspace.

So you will have the following values for each variable:

  • ${workspaceFolder} - /home/your-username/your-project
  • ${workspaceFolderBasename} - your-project
  • ${file} - /home/your-username/your-project/folder/file.ext
  • ${relativeFile} - folder/file.ext
  • ${relativeFileDirname} - folder
  • ${fileBasename} - file.ext
  • ${fileBasenameNoExtension} - file
  • ${fileDirname} - /home/your-username/your-project/folder
  • ${fileExtname} - .ext
  • ${lineNumber} - line number of the cursor
  • ${selectedText} - text selected in your code editor
  • ${execPath} - location of Code.exe

你可能感兴趣的:(vscode 替换变量)