Skip to content

Instantly share code, notes, and snippets.

@natemoo-re
Last active June 24, 2024 09:21
Show Gist options
  • Save natemoo-re/94cfba2bfb17cbeec0680c05309ea9ee to your computer and use it in GitHub Desktop.
Save natemoo-re/94cfba2bfb17cbeec0680c05309ea9ee to your computer and use it in GitHub Desktop.
Visual Studio Code Snippets – Common Case Transformations

Common Case Transformation Snippets

Visual Studio Code allows Snippets to perform ✨Variable Transforms✨ using Regex.

Here are some common case transformations that you can apply to your snippets. In these examples, I'm using $TM_FILENAME_BASE, but the same transformations should apply to any of the Snippet Variables.

snippets-from-delimited.json can convert filenames like my-file-name, my_file_name, my file name. If your filename is delimited by a dash, underscore, or space, these should work.

snippets-from-mixed-case.json can convert filenames like myFileName and MyFileName. If your filename is in camel or Pascal case, these should work.

{
"ConstantCase": {
"prefix": "filename-constant",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/upcase}_${2:/upcase}/g}"
},
"SnakeCase": {
"prefix": "filename-snake",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}_${2:/downcase}/g}"
},
"KebabCase": {
"prefix": "filename-kebab",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}-${2:/downcase}/g}"
},
"CamelCase": {
"prefix": "filename-camel",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}${2:/capitalize}/g}"
},
"PascalCase": {
"prefix": "filename-pascal",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/capitalize}${2:/capitalize}/g}"
}
}
{
"PascalCase": {
"prefix": "filename-pascal",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w)([a-z]+)/${1:/capitalize}${2:/downcase}/g}"
}
}
@wlkns
Copy link

wlkns commented Sep 14, 2023

Thanks @rioj7 I'd tried and been looking for this 👍

@tyler36
Copy link

tyler36 commented Jun 19, 2024

Excellent! I've been looking for this for years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment