vscode:可替换的变量
vscode:可替换的变量。
·
背景
我们在使用 vscode 的时候可能会需要这种变量,今天我们一起查一下文档看看都有什么变量,官方文档地址
说明
- ${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:
- A file located at
/home/your-username/your-project/folder/file.ext
opened in your editor; - The directory
/home/your-username/your-project
opened as your root workspace.
So you will have the following values for each variable:
- ${userHome} -
/home/your-username
- ${workspaceFolder} -
/home/your-username/your-project
- ${workspaceFolderBasename} -
your-project
- ${file} -
/home/your-username/your-project/folder/file.ext
- ${fileWorkspaceFolder} -
/home/your-username/your-project
- ${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
- ${pathSeparator} -
/
on macOS or linux,\
on Windows
更多推荐
已为社区贡献7条内容
所有评论(0)