我用vscode。
我想使用服装片段,但{TM_FILENAME}
有一个扩展名。
如何从中删除扩展名{TM_FILENAME}
?
像这样:`
在文件中MyModule.js
:
转换:${TM_FILENAME/(\w+)\.js/\1/g}
输出:
MyModule
我用vscode。
我想使用服装片段,但{TM_FILENAME}
有一个扩展名。
如何从中删除扩展名{TM_FILENAME}
?
像这样:`
MyModule.js
:转换:${TM_FILENAME/(\w+)\.js/\1/g}
MyModule
您可以使用TM_FILENAME_BASE
仅获取文件名:
${TM_FILENAME_BASE}
实际上,自从提出问题以来,已经添加了一些新的内置变量,包括TM_FILENAME_BASE
. 请参阅片段变量文档。因此,无需进行转换即可获得没有扩展名的文件名。
以下是片段变量的当前列表:
TM_SELECTED_TEXT The currently selected text or the empty string
TM_CURRENT_LINE The contents of the current line
TM_CURRENT_WORD The contents of the word under cursor or the empty string
TM_LINE_INDEX The zero-index based line number
TM_LINE_NUMBER The one-index based line number
TM_FILENAME The filename of the current document
TM_FILENAME_BASE The filename of the current document without its extensions
TM_DIRECTORY The directory of the current document
TM_FILEPATH The full file path of the current document
CLIPBOARD The contents of your clipboard
WORKSPACE_NAME The name of the opened workspace or folder
CURRENT_YEAR The current year
CURRENT_YEAR_SHORT The current year's last two digits
CURRENT_MONTH The month as two digits (example '02')
CURRENT_MONTH_NAME The full name of the month (example 'July')
CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul')
CURRENT_DATE The day of the month
CURRENT_DAY_NAME The name of day (example 'Monday')
CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon')
CURRENT_HOUR The current hour in 24-hour clock format
CURRENT_MINUTE The current minute
CURRENT_SECOND The current second
CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch
For inserting line or block comments, honoring the current language:
BLOCK_COMMENT_START Example output: in PHP /* or in HTML <!--
BLOCK_COMMENT_END Example output: in PHP */ or in HTML -->
LINE_COMMENT Example output: in PHP // or in HTML <!-- -->
The snippet below inserts /* Hello World */ in JavaScript files and <!-- Hello World --> in HTML files:
{
"hello": {
"scope": "javascript,html",
"prefix": "hello",
"body": "$BLOCK_COMMENT_START Hello World $BLOCK_COMMENT_END"
}
}
看起来 v1.40 将添加:
WORKSPACE_FOLDER Path of workspace directory
RANDOM Insert 6 random digits
RANDOM_HEX Insert 6 random hex digits
请参阅https://github.com/microsoft/vscode/pull/82529和https://github.com/microsoft/vscode/pull/79764
v1.53 将添加从根文件夹到当前文件的相对路径:
RELATIVE_FILEPATH
UUID
请参阅https://github.com/microsoft/vscode/pull/114208和https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_53.md#new-snippet-variables
您目前无法执行此操作,但在 vscode GitHub 页面上有您想要的功能请求:https ://github.com/Microsoft/vscode/issues/6920 。
[编辑]
我上面的答案现在已经过时了 - 您可以使用${TM_FILENAME_BASE}
其他贡献者提到的变量。
如果你知道文件扩展名,你可以尝试这样的事情,
${TM_FILENAME/(.js)//}
它将 FileName.js 转换为 FileName