Search code examples
visual-studio-codevscode-snippets

How to get the first letter from the current file for a VSCode snippet?


I'm trying to get the first letter from the current file in order to create a snippet that should look like:

const f = new Object()

Where f is the first letter of the current file. I know I can access to the file name by using TM_FILENAME_BASE, but how can access to the first letter only?


Solution

  • "body": ["${TM_FILENAME_BASE/(.).*/$1/}"],

    (.) capture the first character in group 1
    .* match the rest, you won't use this later but you do want to match it
    $1 replace the entire match with just the first capture group

    In general, you are looking for snippet variable transforms.