当前位置:网站首页>VS Code `launch. Json` and `task Predefined variables available in json`

VS Code `launch. Json` and `task Predefined variables available in json`

2022-06-09 04:03:00 Boy Baoding

brief introduction

VS Code Debuging The configuration file 、Task Variable substitution is supported in the configuration file and some optional settings ,VS Code Variables that support variable substitution in key:value Formal definition , And key and value All strings . stay launch.json and task.json Variable substitution is often used in , The syntax used by variables is : ${variableName} .

Official documents : variables-reference

Predefined variables

VS Code The following variables are predefined :

Suppose that VS Code The file is opened in the editor /home/your-username/your-project/folder/file.ext, Catalog /home/your-username/your-project stay VS Code Open in the root directory of . In this case , The values of the predefined variables are as follows :

  • ${userHome}: Current user home directory of the system

A variable's value : /home/your-username

  • ${workspaceFolder}:VS Code Currently open folder path

A variable's value : /home/your-username/your-project

  • ${workspaceFolderBasename}:VS Code Name of the currently open folder

A variable's value : your-project

  • ${file}: VS Code Currently open file path

A variable's value : /home/your-username/your-project/folder/file.ext

  • ${fileWorkspaceFolder}: VS Code The absolute path of the currently open folder

A variable's value : /home/your-username/your-project

  • ${relativeFile}: be relative to ${workspaceFolder} , The relative path of the currently open file in the editor

A variable's value : folder/file.ext

  • ${relativeFileDirname}: be relative to ${workspaceFolder}, The name of the folder where the currently open file is located in the editor

A variable's value : folder

  • ${fileBasename}: Edit the current file name opened in , With suffix

A variable's value : file.ext

  • ${fileBasenameNoExtension}: Edit the current file name opened in , No suffix

A variable's value : file

  • ${fileDirname}: The absolute path of the folder where the currently open file is located in the editor

A variable's value : /home/your-username/your-project/folder

  • ${fileExtname}: The suffix of the currently open file in the editor

A variable's value : .ext

  • ${cwd}:the task runner’s current working directory upon the startup of VS Code

A variable's value :-

  • ${lineNumber}:the current selected line number in the active file

A variable's value : -

  • ${selectedText}: The text currently selected in the active state file with the editor open

A variable's value : The currently selected text

  • ${execPath}:Code.exe/code The absolute path of the executable program

A variable's value : Code.exe/code The absolute path of the executable program (location of Code.exe)

  • ${defaultBuildTask}:the name of the default build task

A variable's value :the name of the default build task

  • ${pathSeparator}:the character used by the operating system to separate components in file paths

A variable's value : / on macOS or linux, \ on Windows

Tip: stay tasks.json and launch.json Use predefined variables in ,VS Code intellisense (IntelliSense) A list of predefined variables will be provided dynamically .

Refer to the official documentation for more variables : variables-reference

原网站

版权声明
本文为[Boy Baoding]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090403019012.html