I use vscode.
I want to use costum snippets, but {TM_FILENAME}
has an extension name.
How can I delete the extension from {TM_FILENAME}
?
like this:`
MyModule.js
:Transform: ${TM_FILENAME/(\w+)\.js/\1/g}
MyModule
Snippet variables have become a staple of Yoast SEO. These variables make it possible to automate certain processes on your site. They also make it easy to change large batches of meta descriptions for instance, since you only have to change the structure of the variable – the site fills in the data automatically.
You can use TM_FILENAME_BASE
to get only the filename:
${TM_FILENAME_BASE}
Actually, since the question was posed a few new built-in variables have been added,
including TM_FILENAME_BASE
. See snippet variables documentation. So there is no need to do a transform just to get the filename without the extension.
Here is the current list of snippet variables:
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 <!-- -->
vscode v1.66 will add two new variables:
CURSOR_INDEX 0-based
CURSOR_NUMBER 1-based
The above two work with multiple cursors so that each cursor position (same as a selection) will have an incremented integer inserted.
For an example of this, see https://stackoverflow.com/a/69946559/836330
It looks like v1.40 will add:
WORKSPACE_FOLDER Path of workspace directory
RANDOM Insert 6 random digits
RANDOM_HEX Insert 6 random hex digits
See https://github.com/microsoft/vscode/pull/82529 and https://github.com/microsoft/vscode/pull/79764
v1.53 will add the relative path from the root folder to the current file:
RELATIVE_FILEPATH
UUID
See https://github.com/microsoft/vscode/pull/114208 and https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_53.md#new-snippet-variables
You can't do this at the moment but there's a feature request on the vscode GitHub page for what you want: https://github.com/Microsoft/vscode/issues/6920.
[EDIT]
My answer above is now out of date - you can use the ${TM_FILENAME_BASE}
variable as mentioned by other contributors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With