Search code examples
angulartypescriptvisual-studio-codecode-snippets

Visual studio code: replace char case while typing in snippet


I'm trying to write code-snippet for Visual Studio Code and TypeScript. So far I managed to mirror typed word like this:

import { ${1:Name}Component } from './${1:name}.component';

When I type the word in place #1 it is mirrored to place #2 like this:

import { MynameComponent } from './Myname.component';

Is it possible to change snippet so the place #2 is in lower case like this:

import { MynameComponent } from './myname.component';

Solution

  • The ability to transform snippets has been more recently added in vscode v.1.25. In your case try this snippet:

    "import components": {
        "prefix": "isml",
        "body": [
          "import { ${1/(.*)/$1Component } from '.\\/${1:/downcase}/}.component'",
        ],
        "description": "small"
      },
    

    Trigger the prefix. Then hit tab after you enter your component name (Myname in this example) and it will complete the snippet as you wanted.

    import { MynameComponent } from './myname.component';