VSCode Snippets: Format File Name from my_file_name to MyFileName

468

It's as easy as that: ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}

Share:
468
mrgnhnt96
Author by

mrgnhnt96

I love Flutter!

Updated on December 15, 2022

Comments

  • mrgnhnt96
    mrgnhnt96 over 1 year

    I am creating custom snippets for flutter/dart. My goal is to pull the file name (TM_FILENAME_BASE) remove all of the underscores and convert it to PascalCase (or camelCase).

    Here is a link to what I have learned so far regarding regex and vscode's snippets. https://code.visualstudio.com/docs/editor/userdefinedsnippets

    I have been able to remove the underscores nicely with the following code

        ${TM_FILENAME_BASE/[\\_]/ /}
    

    I can even make it all caps

        ${TM_FILENAME_BASE/(.*)/${1:/upcase}/}
    

    However, it seems that I cannot do two steps at a time. I am not familiar with regex, this is just me fiddling around with this for the last couple of days.

    If anyone could help out a fellow programmer just trying make coding simpler, it would be really appreciated!

    I expect the output of "my_file_name" to be "MyFileName".