Skip to content

Instantly share code, notes, and snippets.

@cmstead
Last active March 3, 2024 06:40
Show Gist options
  • Save cmstead/7ad64539d13dfdb5a2591bc3be3c8eeb to your computer and use it in GitHub Desktop.
Save cmstead/7ad64539d13dfdb5a2591bc3be3c8eeb to your computer and use it in GitHub Desktop.
VS Code snippet transform: convert camel case to Pascal case or vice versa
// If you want to convert a PascalCase variable to camelCase, you can do the following:
// Where `n` is the tab stop you want to reference
${n/^(.)(.*)$/${1:/downcase}${2}/}
// Example: ${1:This is my original} => ${1/^(.)(.*)$/${1:/downcase}${2}/}
// If you want to convert a camelCase variable to PascalCase, you can do the following:
// Where `n` is the tab stop you want to reference
${n/^(.)(.*)$/${1:/upcase}${2}/}
// Example: ${1:This is my original} => ${1/^(.)(.*)$/${1:/upcase}${2}/}
@programmermark
Copy link

thank you

@viktor-evdokimov
Copy link

viktor-evdokimov commented Oct 5, 2022

Answer to vscode snippet transform file name in the snippet to camel case or pascal case variable

given file_name_foo.ext file

${TM_FILENAME_BASE/^(.*)_foo$/${1:/pascalcase}/}  ==> FileName
${TM_FILENAME_BASE/^(.*)_foo$/${1}/}  ==> file_name
${TM_FILENAME_BASE/^(.*)_foo$/${1:/upcase}/}  ==> FILE_NAME

@alicerocheman
Copy link

alicerocheman commented Oct 13, 2022

:/camelcase works as well.

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